csharp:: 물음표 연산자_? ?? nullable operator

string tmp = {condition} ? {return value if TRUE} : {return value if FALSE}

 

var rand = new Random();
var condition = rand.NextDouble() > 0.5;


// int? 로 표기하여, int에 null을 넣을 수 있음
int? x = condition ? 12 : null;

IEnumerable<int> xs = x is null ? new List<int>() { 0, 1 } : new int[] { 2, 3 };

 

 

 

 

https://skuld2000.tistory.com/17

 

[C#/.NET] Nullable : ? (Null 조건 연산자)

코딩을 하다보면 인자로 넘긴 primitive 타입의 변수를 2가지 용도로 사용하는 경우가 있다. 예를 들면 int 형 변수를 갯수로 사용하기 위해 넘기되 그 값을 정상적인 상황에서 들어가지 않을 값으

skuld2000.tistory.com

 

 

 

 

https://learn.microsoft.com/ko-kr/dotnet/csharp/language-reference/builtin-types/nullable-value-types

 

Null 허용 값 형식 - C# 참조

C# nullable 값 형식 및 사용 방법 알아보기

learn.microsoft.com

 

 

https://www.csharpstudy.com/CS6/CSharp-null-conditional-operator.aspx

 

C# 6.0 널 조건 연산자 - C# 프로그래밍 배우기 (Learn C# Programming)

널 조건 연산자 (Null-conditional operator) C# 프로그래밍에서 NULL 체크만큼 많은 시간을 할애하는 곳도 아마 드물 것이다. 즉, 객체의 메서드나 속성을 사용하기 전에 객체가 NULL인지 항상 체크해 줘야

www.csharpstudy.com

 

 

 

https://learn.microsoft.com/ko-kr/dotnet/csharp/language-reference/operators/conditional-operator

 

?: 연산자 - 3차 조건부 연산자

부울 식의 결과를 기반으로 두 식 중 하나의 결과를 반환하는 C# 3차 조건 연산자('?:')에 대해 알아봅니다.

learn.microsoft.com

 

 

 

https://error999.tistory.com/22

 

C# - 물음표 연산자(?, ??), 삼항연산자

코드를 작성할 때 null 처리와 단순 if else 조건을 처리할 때 '단순한 조건때문에 줄을 더 써야하나?' 라고 생각할 수 있습니다. 아주 간단한 조건인데도 불구하고 한줄로 쓸 수 있는 코드에 4줄이

error999.tistory.com

 

 

 

 

 

 

반응형