68. 추가연산자 ( is / as / ?? 연산자 )
.NET프로그래밍/C# 3.5 SP1 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;
}
}
}
'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글
70. 암시적으로 형식화된 로컬 변수 (0) | 2009.08.17 |
---|---|
69. 분할클래스(partial class) (0) | 2009.08.17 |
67. 값형식과 참조형식(Boxing과 UnBoxing) (0) | 2009.08.17 |
66. Nullable형식(=Null가능형식) (0) | 2009.08.17 |
65. 명령줄인수 (0) | 2009.08.17 |