프로그래밍/C#
[C#] 타입과 변수의 특징
갓똥
2020. 1. 20. 23:27
728x90
반응형
1. 핵심 정리
using System;
class Program {
public static void Main() {
// int n1;
// Console.WriteLine(n1); - error
int n1 = 10;
Console.WriteLine(n1);
// double n2 = 10;
// int n3 = n2;
double n2 = 10;
var n3 = n2;
}
}
① 초기화 되지 않은 변수는 사용(Read)할 수 없다.
② var (C++의 auto)
=> 우변의 타입에 따라 좌변의 타입이 결정
=> 프로그래밍을 하며 데이터 타입이 바뀔 때 유용
2. 추가 특징
using System;
class Program {
public static void Main() {
10.ToString();
int n = 10; // System.Int32
string s1 = "AAA";
String s2 = "AAA";
System.String s3 = "AAA";
System.Int32 n2 = 10;
Int32 n3 = 10;
}
}
① C#에서 모든 것은 객체이다.
=> 10, 3.4, "AAA"도 모두 객체이다. (멤버를 가지고 있다.)
② C#의 타입과 .net framework
728x90
반응형