てぃぐれのプログラマwiki

ワクワクに従う

??演算子 【C#】

経緯

??の使い方についてこんがらがるのでみていく。

??  NULL合体演算子 null-coalescing-operator

??= NULL合体代入演算子

 

 

コード

string y = null;

Console.WriteLine(y ?? "test null"); // test null

int? i = 2;

i ??= -1; //iがnullなら-1をいれる

Console.WriteLine(i); //2