null 조건부
using static System.Console;
using System.Collections;
namespace Practice01
{
class Class1
{
static void Main()
{
ArrayList arrayList = null;
WriteLine(arrayList); // null
arrayList = new ArrayList();
arrayList.Add(1);
arrayList.Add(2);
// null인지 판별
WriteLine($"array의 개수는? : {arrayList?.Count}");
}
}
}
null 병합
int a = null;
// a는 null이기 때문에 0을 반환
Console.log($"{a ?? 0}");
a = 22;
// a는 null이 아니기 때문에 값(22)을 반환
Console.log($"{a ?? 0}");
[C#] foreach (0) | 2022.09.13 |
---|---|
[C#] Switch문 -> Switch식으로 변경 (0) | 2022.09.13 |
[C#] 날짜 서식화 (0) | 2022.08.11 |
[C#] 숫자 서식화 (0) | 2022.08.11 |
[C#] 문자열 서식 (0) | 2022.08.11 |
댓글 영역