| void main() { |
| print('Hello Code Factory'); |
| } |
| |
| |
| |
- var : 선언된 값에 의해서 var 타입이 지정됨
- dynamic : 선언된 값에 위해서 var 타입이 지정됨
- 숫자 : int, double
| void main() { |
| int number1 = 12; |
| |
| print(number1); |
| |
| int number2 = 38; |
| |
| print(number2); |
| |
| print(number1 + number2); |
| print(number1 - number2); |
| print(number1 * number2); |
| print(number1 / number2); |
| |
| print('-----------------'); |
| |
| double number3 = 2.5; |
| double number4 = 0.5; |
| |
| print(number3); |
| print(number4); |
| |
| print(number3 + number4); |
| print(number3 - number4); |
| print(number3 * number4); |
| print(number3 / number4); |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
- 문자 : String
-
- $ 를 사용하여 문자 합치기, 변수 사용하기 가능
| void main() { |
| String name = '코드팩토리'; |
| |
| print(name); |
| |
| String name2 = '슬기'; |
| String sentence = '는 레드벨벳 멤버입니다.'; |
| |
| print(name2 + sentence); |
| print('$name2$sentence'); |
| |
| int count = 5; |
| String sentence2 = '레드벨벳 멤버는 $count명 입니다.'; |
| print(sentence2); |
| } |
| |
| |
| |
| |
| |
| |
| void main() { |
| bool isTrue = true; |
| bool isFalse = false; |
| |
| print(isTrue); |
| print(isFalse); |
| } |
| |
| |
| |
| |
- [] 사용
- 생성
List redVelvetList = [];
- 추가
| redVelvetList.add('아이린'); // 추가 방법 |
| redVelvetList.add('슬기'); |
| redVelvetList.add('조이'); |
- 삭제
redVelvetList.removeAt(1); // 삭제 방법
- 인덱스 조회
| print(redVelvetList[0]); |
| print(redVelvetList[1]); |
- 인덱스 내용 변경
redVelvetList[0] = '코드팩토리'
| void main() { |
| List redVelvetList = []; |
| |
| print(redVelvetList); |
| |
| redVelvetList.add('아이린'); |
| redVelvetList.add('슬기'); |
| redVelvetList.add('조이'); |
| |
| print('------------------'); |
| print(redVelvetList); |
| |
| redVelvetList.removeAt(1); |
| |
| print(redVelvetList); |
| |
| print(redVelvetList[0]); |
| print(redVelvetList[1]); |
| |
| redVelvetList[0] = '코드팩토리'; |
| |
| print(redVelvetList); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
- 타입 지정 리스트
| void main() { |
| List<String> redVelvetList = []; |
| |
| redVelvetList.add('슬기'); |
| |
| print(redVelvetList); |
| } |
| |
| |
| |
- 값 지정
| void main() { |
| List redVelvetList = [ |
| '아이린', |
| '슬기', |
| '웬디', |
| '조이', |
| '예리' |
| ]; |
| |
| print(redVelvetList); |
| |
| List redVelvetList2 = new List.from([ |
| '아이린', |
| '슬기', |
| '웬디', |
| '조이', |
| '예리' |
| ]); |
| |
| print(redVelvetList2); |
| } |
| |
| |
| |
| |
- 리스트 길이 : length
| void main() { |
| List redVelvetList = [ |
| '아이린', |
| '슬기', |
| '웬디', |
| '조이', |
| '예리' |
| ]; |
| |
| print(redVelvetList); |
| |
| List redVelvetList2 = new List.from([ |
| '아이린', |
| '슬기', |
| '웬디', |
| '조이', |
| '예리' |
| ]); |
| |
| print(redVelvetList2); |
| |
| print(redVelvetList.length); |
| } |
| |
| |
| |
| |
| |
- { } 사용
- 생성
| Map dictionary = { |
| 'apple' : '사과', |
| 'banana' : '바나나', |
| 'watermelon' : '수박', |
| }; |
- 조회
| print(dictionary['apple']); |
| print(dictionary['banana']); |
- 삭제
dictionary2.remove('apple');
- 키로 값 변경
dictionary2['banana'] = '코드팩토리';
| void main() { |
| Map dictionary = { |
| 'apple' : '사과', |
| 'banana' : '바나나', |
| 'watermelon' : '수박', |
| }; |
| |
| print(dictionary); |
| |
| print(dictionary['apple']); |
| print(dictionary['banana']); |
| |
| Map dictionary2 = {}; |
| print('---------'); |
| |
| dictionary2.addAll({ |
| 'apple' : '사과', |
| 'banana' : '바나나', |
| 'watermelon' : '수박', |
| }); |
| |
| print(dictionary2); |
| |
| dictionary2.remove('apple'); |
| |
| print(dictionary2); |
| |
| dictionary2['banana'] = '코드팩토리'; |
| |
| print(dictionary2); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void main() { |
| Map dictionary = {}; |
| |
| Map dictionary2 = new Map(); |
| |
| Map dictionary3 = new Map.from({ |
| 'apple':'사과', |
| 'banana':'바나나', |
| }); |
| |
| print(dictionary3); |
| |
| print(dictionary3.keys.toList()); |
| print(dictionary3.values.toList()); |
| |
| Map<String, int> price = { |
| 'apple': 2000, |
| 'banana': 4000, |
| 'watermelon': 6000, |
| }; |
| |
| print(price); |
| |
| dictionary3.addAll({ |
| 'apple': '수박' |
| }); |
| |
| print(dictionary3); |
| } |
| |
| |
| |
| |
| |
| |
| |