728x90
nullable이란?
nullable은 기본적변수에 null 값을 넣을수있게 만드는것이다.
1 | int? a = null; |
이렇게 선언할수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Nullable { class Program { static void Main(string[] args) { int? a = null; if (a.HasValue) { Console.WriteLine(a); } else { Console.WriteLine("null 값입니다."); } } } } | cs |
이렇게 사용할수있다.
HasValue값이 true 이면 a변수에 null 값이 아닌것이고 HasValue값이 false이면 a변수가 null 값을 가진다.
1 | int b = a ?? -1; | cs |
int? a 값이 null 이면 b에 -1들어가며 만약에 a가 null 아닌 다른값을 가지면
b에 그값이 들어간다.
'언어 > Unity' 카테고리의 다른 글
[Unity}RayCast (0) | 2018.01.31 |
---|---|
[Unity] GUI 만들기 (0) | 2018.01.29 |
[Unity]List사용 (0) | 2018.01.24 |
[Unity]대리자를 이용한 콜백함수 만들기 (958) | 2018.01.22 |
[Unity]대리자 delegate (20) | 2018.01.20 |