자료형별로 별도의 초기화하지 않으면 기본적으로 적용되는 값들이 있음
- Type
bool - false
double - 0.0D
float - 0.0F
int - 0
string - null
- Array
해당 배열의 타입인 자료형 기본값을 따라감.
From section 7.6.10.4 of the C# 5 specification:
All elements of the new array instance are initialized to their default values (§5.2).
And from section 5.2:
The default value of a variable depends on the type of the variable and is determined as follows:
- For a variable of a value-type, the default value is the same as the value computed by the value-type’s default constructor (§4.1.2).
- For a variable of a reference-type, the default value is null.
Initialization to default values is typically done by having the memory manager or garbage collector initialize memory to all-bits-zero before it is allocated for use. For this reason, it is convenient to use all-bits-zero to represent the null reference.
'Csharp' 카테고리의 다른 글
C# - 코딩할 때 도움되는 자잘한 문법들 (2) | 2019.08.05 |
---|---|
C#/WPF - 문자열로 객체 접근하는 법에 대한 해답 (0) | 2019.08.05 |
C# - 외부 프로그램과 링크 실행, 종료 (0) | 2019.07.22 |
WPF - 다른 파일에서 Window.xaml.cs 코드 접근 (0) | 2019.07.22 |
WPF - Tray icon(트레이 아이콘) 과 메뉴 추가, 관리하기 (0) | 2019.07.15 |