반응형
정수형 등의 변수는 반드시 초기화해서 사용해야 한다.
변수 선언시 ?를 붙이면 null 값으로 초기화할 수 있다.
| Program.cs |
| using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Nulilable { class Program { static void Main(string[] args) { int i = 100; //double nd = null; // ? 붙이지 않으면 null값으로 처리안됨 int? ni = null; double? nd = 12.34; if (ni.HasValue) { //널값이면 false, 값이 있으면 참 Console.WriteLine("{0}", ni.Value); } else { Console.WriteLine("널값입니다"); } } } } |
결과화면
65.Nulilable.zip반응형
'C#' 카테고리의 다른 글
| 66.C# - 추가연산자 (0) | 2009.08.17 |
|---|---|
| 65.C# - 값형식과 참조형식 ( Boxing 과 UnBoxing ) (0) | 2009.08.17 |
| 64.C# - 명령줄인수 - 2 - ( command Line Prompt ) (0) | 2009.08.17 |
| 63.C# - 명령줄인수 ( Commands Line Prompt ) (0) | 2009.08.17 |
| 62.C# - 봉인클래스 (sealed Class) (0) | 2009.08.15 |
Comments