변수

송민경's avatar
Apr 05, 2024
변수

1. 컴파일이 없음 → 바로 실행하는 것

notion image
notion image

2. 변수 사용하기

  • 파일 스캔 부터 일어나서 바이트가 할당됨
print(); // 출력하기
int n1 = 1; // 정수 double d1 = 10.1; // 소수 bool b1 = true; // true, false String s1 = "홍길동"; // 문자열 void main() { print(n1); print(d1); print(b1); print(s1); }
notion image
 

3. 타입 확인하기

runtimeType // 타입확인
int n1 = 1; double d1 = 10.1; bool b1 = true; String s1 = "홍길동"; void main() { print(n1.runtimeType); print(d1); print(b1); print(s1); }
notion image
 

4. 형 변환 하는 방법

int n1 = 1; double d1 = 10.1; bool b1 = true; String s1 = "홍길동"; void main() { print(n1.runtimeType); print("d1 + " + d1.toString()); // 형 변환 print"b1); print(s1); }
notion image

5. 변수 이름과 출력값 같이 출력하기

int n1 = 1; double d1 = 10.1; bool b1 = true; String s1 = "홍길동"; void main() { print(n1.runtimeType); print("d1 + " + d1.toString()); print("b1: ${b1}"); print(s1); }
notion image
 

6. 문자열 변수를 선언하고 초기화

String secret = "홍길동";
notion image
 

7. var과 dynamic

  • 값이 한번 정해지면 타입 변경 불가능
var n1 = 1; void main() { print(n1.runtimeType); }
  • 타입 변경 가능
var n1 = 1; dynamic n2 = 2; void main() { print(n1.runtimeType); print(n2.runtimeType); // 타입 변경이 가능함 // n1 = 2.0 // var은 값이 한번 정해지면 타입 변경 불가능 n2 = 2.0; print(n2.runtimeType); }
notion image
Share article
RSSPowered by inblog