๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
TIL

20230404 TIL

by ๊น€๋นต๊ทธ 2023. 4. 4.

๐Ÿค“Today ์š”์•ฝ

1. data type List[], set{}...
2. ๋ฐฐ์—ด, ํ…์ŠคํŠธ๋ผ๋ฆฌ ๋น„๊ตํ•˜๋ฉด์„œ ์—ฐ์‚ฐํ•  ์‹œ reduce๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ข€ ๋” ํŽธ๋ฆฌํ•˜๋‹ค. for๋ฌธ์„ ์ตœ์†Œํ™”ํ–ˆ์œผ๋ฉด ์ข‹๊ฒ ๋‹ค. 
3. ๋ณ€์ˆ˜๊ฐ€ null์ด ๋  ์ˆ˜๋„, ์•„๋‹์ˆ˜๋„ ์žˆ์„ ์‹œ ?? ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌ๋ถ„์ง“๋Š”๋‹ค

 


 

๐Ÿ‘ 1. ์ž˜ํ•œ ์ 

 - ์ฑŒ๋ฆฐ์ง€ ์„ฑ๊ณต (10/11)

- ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”ํ…Œ ํ•˜๋Š” ๋ฐ ๊ตฌ๊ธ€๋ง์ด ์ข€ ๋” ์ค€ ๊ฒƒ

โœŒ๏ธ 2. ๊ฐœ์„  ์ 

- ๊ธฐ์ดˆ ๊ณต๋ถ€๋ฅผ ๊พธ์ค€ํžˆ ํ•ด์•ผ๊ฒ ๋‹ค. ์‰ฝ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์—ฌ ๋ฐ”๋กœ ๋„˜์–ด๊ฐ„ ์ฑ•ํ„ฐ์˜€๋Š”๋ฐ, ์ฑŒ๋ฆฐ์ง€๋ฅผ ํ•˜๋‹ค๋ณด๋‹ˆ ๋ถ€์กฑํ–ˆ๋˜ ๊ธฐ๋ณธ ์ง€์‹๋“ค์„ ์ข€ ๋” ์ฑ„์›Œ๋‚˜๊ฐ€๋Š” ๊ธฐ๋ถ„

๐Ÿ‘ 3. ๋ฐฐ์šด ์ 

Dart Data types 

- List, for, if, map, set 

https://252-archive.tistory.com/6

 

Dart Data types

Dart ๋ฐ์ดํ„ฐ ํƒ€์ž… 1. Basic Data Types void main(){ String name = "hi~"; bool alive = true; int age = 20; double money = 12.11; num x = 12; x = 12.99; } ๊ธฐ๋ณธ์ ์œผ๋กœ String = "" / bool = true, false / int = "12" / double = "22.21"๊ฐ€ ์žˆ๋‹ค int์™€ do

252-archive.tistory.com

 

Dart Factory Constructor

  • Return ํŒฉํ† ๋ฆฌ ์ƒ์„ฑ์ž์—์„œ ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค.
  • name constructor๋ณด๋‹ค ๋” ์œ ์—ฐํ•˜๋‹ค
  • ์ƒ์„ฑ์ž๋Š” ํด๋ž˜์Šค ์ž์ฒด์˜ ์ƒˆ ์ธ์Šคํ„ด์Šค๋งŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ํŒฉํ† ๋ฆฌ ์ƒ์„ฑ์ž๋Š” ํด๋ž˜์Šค ๊ธฐ์กด ์ธ์Šคํ„ด์Šค ๋˜๋Š” ํ•˜์œ„ ํด๋ž˜์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ์™œ factory constructor๊ฐ€ ํ•„์š”ํ•œ๊ฐ€? ๋ฐฉ์–ด ์ฝ”๋”ฉ, ํ•„์ˆ˜๋Š” ์•„๋‹ˆ์ง€๋งŒ ์œ ์ง€ ๊ด€๋ฆฌ์— ์œ ์šฉํ•˜๋‹ค.

 

Dart Object

 

์˜ˆ์‹œ
void main(){
	Leg newLeg = Leg(); 
	Leg newLeg2 = newLeg; 
	
	print("newLeg2.legs - ${newLeg2.legs}"); //newLeg2.legs - 2
	newLeg.legs = 4; 
	print("newLeg2.legs after- ${newLeg2.legs}"); ////newLeg2.legs after - 4
}
class Leg {
	int legs = 2;
}

 

  • object๋Š” instace๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” ์ €์žฅ ๊ณต๊ฐ„์˜ ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง„ ๋ ˆํผ๋Ÿฐ์Šค์ด๋‹ค

 

Static variable

  • global variable : class ๋ฐ”๊นฅ์— ์œ„์น˜ํ•œ, ์–ด๋””์„œ๋‚˜ ์ ‘๊ทผ ๊ฐ€๋Šฅ
  • class variable : class ์•ˆ์— ์œ„์น˜ํ•œ static variable
  • instance variable : class ์•ˆ์— ์œ„์น˜ํ•œ variable. static ์•„๋‹˜ 
  • local variable : method ์•ˆ์— ์œ„์น˜ํ•œvariable

 

reduce()

  • reduce ((a, b) => a+b); 
  • ์ œ๋ฐœ ์žŠ์–ด๋ฒ„๋ฆฌ์ง€ ๋ง์ž ..

 

Nullabel 

  • No value ๋˜๋Š” value๊ฐ€ ์—†๋‹ค
  • null์ด int๊ฐ’์— ์ €์žฅ์ด ๋  ์ˆ˜ ์—†๋‹ค 
์˜ˆ์‹œ > ์—๋Ÿฌ ๋ฐœ์ƒ 
class Car {
  int totalDistance = null;
  
  int getCurrentTotalDistance(){
    int thisTripDistance = 32;
    return totalDistance + thisTripDistance;
  }
}

 

  • null์„ ์ €์žฅํ•˜๊ณ  ์‹ถ์„์‹œ type ๋’ค์— ๋ฌผ์Œํ‘œ?๋ฅผ ๋ถ™์ธ๋‹ค
int? postCode = null;
String? name = null;
double? myHeight = null;
bool? haveMoney = null;

 

 

 

 

'TIL' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

20230410 TIL  (0) 2023.04.10
20230407 TIL  (0) 2023.04.07
20230406 TIL  (0) 2023.04.06
20230405 TIL  (0) 2023.04.05
20230403 TIL  (0) 2023.04.03