C# “Coalescing operator” ile kolay null kontrolü

HZ.CİN

Cin Terbiyecisi
Ultra Member
Joined
Dec 22, 2019
Topics
243
Messages
385
Reaction score
62
Location
Cehennem
Aşağıdaki örnekte, test string’ine testStr1‘in değeri null değilse atanacak, şayet null ise testStr2 atanacaktır. Eğer testStr2 de null ise boş string ataması yapılacaktır. (Deneyerek görmeniz, bu cümleleri okuyup anlamanızdan çok daha kolay olacaktır gibi geliyor bana)

C#:
string test = testStr1 ?? testStr2 ?? string.Empty
 

Top