This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Program | |
{ | |
class MainApp | |
{ | |
static void Main(string[] args) | |
{ | |
int? a = null; | |
// 데이터타입? 변수이름 은 Nullable 타입(비어있는 상태 가능) | |
// 값 형식은 기본 비어있을 수 없기에, 값 타입만 ?를 사용해서 Nullable타입으로 변환 해주면 사용 가능. | |
// 참조형식은 null값이 기본 대입 가능. | |
Console.WriteLine(a.HasValue); | |
// .HasValue 프로퍼티는 값이 있냐 없냐. nullable 검사(nullable타입 사용 시 확인) | |
Console.WriteLine(a != null); | |
a = 3; | |
Console.WriteLine(a.HasValue); | |
Console.WriteLine(a != null); | |
Console.WriteLine(a.Value); | |
// .Value 프로퍼티는 무슨 값이냐? | |
} | |
} | |
} |
반응형
'Programming > C# - Window' 카테고리의 다른 글
C#/ 문자열 서식 (1) | 2023.06.27 |
---|---|
C#/ var (0) | 2023.06.27 |
C#/ 상수(const)와 열거(enum) 형식 (1) | 2023.06.27 |
C#/ 숫자 - 문자열 사이 타입 변환(type casting) (0) | 2023.06.27 |
C#/ object형식(박싱과 언박싱) (0) | 2023.06.27 |