Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Null 처리 #21

Closed
SAgiKPJH opened this issue Jul 2, 2024 · 0 comments
Closed

C# Null 처리 #21

SAgiKPJH opened this issue Jul 2, 2024 · 0 comments

Comments

@SAgiKPJH
Copy link
Contributor

SAgiKPJH commented Jul 2, 2024

!

  • 해당 객체가 null이 아님을 확신하는 null-forgiving operator연산자 (C# 8.0부터 도입)
  • null이 들어오는 경우 NullReferenceException 발생
Id = vo.InferenceImage!.Id;

?.

  • null 조건부 연산자로, null이 아닌경우 속성 값 반환, 그렇지 않으면 null 반환
  • null인지 확인한 뒤 처리합니다.
    • ?[] 조던 인덱서로도 활용 가능
Id = vo.InferenceImage?.Id,

??

  • null 병합 연산자로, null인 경우 오른쪽 피연산자를 활용합니다.
// null인 경우 할당
myString ??= "default value";

// person?.Name이 Null이면 "Unknown"이 name에 할당됩니다.
string name = person?.Name ?? "Unknown";

int? length = array?[index] ?? 0;
@SAgiKPJH SAgiKPJH closed this as completed Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant