programing

VB.NET null 병합 연산자?

muds 2023. 5. 26. 22:51
반응형

VB.NET null 병합 연산자?

중복 가능성:
VB.NET의 병합 연산자 및 조건 연산자
C#에 해당하는 VB.NET이 있습니까?교환원?

C# null 병합 연산자에 해당하는 내장 VB.NET이 있습니까?

예, VB 9 이상(Visual Studio 2008에 포함)을 사용하는 경우가 있습니다.

오버로드된 연산자의 버전을 사용하여 두 개의 인수만 허용할 수 있습니다.

Dim myVar? As Integer = Nothing
Console.WriteLine(If(myVar, 7))

자세한 내용은 VB.NET 팀의 블로그 게시물에서 확인할 수 있습니다.

(네, 이것은 함수처럼 보이지만 연산자입니다.C#의 "적절한" 널 병합 연산자와 동일한 IL로 컴파일됩니다.)

Dim b As Boolean?
Console.WriteLine("{0}.", If(b, "this is expected when b is nothing"))
'output: this is expected when b is nothing.

b = False
Console.WriteLine("{0}.", If(b, "this is unexpected when b is false"))
'output: False.

b = True
Console.WriteLine("{0}.", If(b, "this is unexpected when b is true"))
'output: True.

질문에 따르면 답은 If()인 것 같습니다.

아니요. 사용GetValueOrDefault그래서 거기에 있는 거예요!

저는 VB에 내장되어 있다고 생각하지 않습니다.순 등가이지만 여기 답이 있습니다: VB의 Null 병합 연산자입니다.네트(8)

언급URL : https://stackoverflow.com/questions/6792729/vb-net-null-coalescing-operator

반응형