.NET프로그래밍/C# 3.5 SP1
68. 추가연산자 ( is / as / ?? 연산자 )
holland14
2009. 8. 17. 10:34
// 참조타입 관련 연산자
// is 연산자 : str is string : str변수가 string 형식인지 검사 : bool값
// as 연산자 : (str is string) ? str: null; : is 연산자 + ?: 연산자
// ?? 연산자
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 추가연산자
{
class Program
{
static void Main(string[] args)
{
int i = 10; // 값형식은 사용 불가
string s = "안녕";
object o = s;
int? num = null; // ?? 연산자는 Nullable
Console.WriteLine("{0}", (o is string) ); // True
Console.WriteLine("{0}", (o as string) ); // (o is string) ? o : null;
Console.WriteLine("{0}", (num ?? 1234) ); // 의미 -> (num is null) ? 1234 : num;
}
}
}