C#
66.C# - 추가연산자
Godffs
2009. 8. 17. 21:28
반응형
참조타입 관련 연산 예제 입니다.
Program.cs |
using System; class 추가연산자 { static void Main(string[] args) { int i = 10; //값 형식은 사용불가 (기본) string s = "안녕"; object o = "Hi"; int? num = null; // ??연산자는 Nullalbe 가능 Console.WriteLine("{0}", o is string); //True Console.WriteLine("{0}", o as string); //(o is string) ? o :null //변환 그렇지 않으면 null Console.WriteLine("{0}", (num ?? 1234) ); //(num is null)?1234 : num; } //널 오브 타입은 ??로 비교 } |
결과화면
반응형