๐ค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 |