43 lines
711 B
C#
43 lines
711 B
C#
class CSVar
|
|
{
|
|
//필드 (클래스 내에서 공통적으로 사용되는 전역 변수)
|
|
int globalVar;
|
|
const int MAX = 1024;
|
|
|
|
public void Method1()
|
|
{
|
|
// 로컬변수
|
|
int localVar;
|
|
|
|
// 아래 할당이 없으면 에러 발생
|
|
localVar = 100;
|
|
|
|
Console.WriteLine(globalVar);
|
|
Console.WriteLine(localVar);
|
|
}
|
|
}
|
|
|
|
class CSVar2
|
|
{
|
|
// 상수
|
|
const int MAX_VALUE = 1024;
|
|
|
|
// readonly 필드
|
|
readonly int Max;
|
|
public CSVar2()
|
|
{
|
|
Max = 1;
|
|
}
|
|
|
|
//...
|
|
}
|
|
|
|
internal class Program
|
|
{
|
|
private static void Main(string[] args)
|
|
{
|
|
// 테스트
|
|
CSVar obj = new CSVar();
|
|
obj.Method1();
|
|
}
|
|
} |