Console.WriteLine(default(int)); // output: 0
Console.WriteLine(default(object) is null); // output: True
void DisplayDefaultOf<T>()
{
var val = default(T);
Console.WriteLine($"Default value of {typeof(T)} is {(val == null ? "null" : val.ToString())}.");
}
DisplayDefaultOf<int?>();
DisplayDefaultOf<System.Numerics.Complex>();
DisplayDefaultOf<System.Collections.Generic.List<int>>();
// Output:
// Default value of System.Nullable`1[System.Int32] is null.
// Default value of System.Numerics.Complex is (0, 0).
// Default value of System.Collections.Generic.List`1[System.Int32] is null.
ref : https://learn.microsoft.com/ko-kr/dotnet/csharp/language-reference/operators/default
반응형
'프로그래밍(Programming) > C#' 카테고리의 다른 글
linq (3) (0) | 2023.04.10 |
---|---|
linq (2) (0) | 2023.04.09 |
Linq (1) (0) | 2023.04.08 |
async/await & 커피와 베이컨 (0) | 2023.04.07 |
C# - ArraySegment (0) | 2023.01.04 |