Csharp

C# - 자료형들의 기본값

sckwon770 2019. 7. 22. 22:16

 

 

자료형별로 별도의 초기화하지 않으면 기본적으로 적용되는 값들이 있음

 

- 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.