The Easiest NULL checks in C# #shorts



In C#, ?? operator is known as Null-coalescing operator. The null coalescing operator was introduced in C# 7.0 and use double question marks as its syntax. It will return the value of its left-hand operand if it is not null. If it is null, then it will evaluate the right-hand operand and returns its result.

#shorts #dotnet #dotnetprogramming #dotnet6 #programming #csharp #programmingforbeginners #csharp #csharptutorial #csharpdotnet #aspnetcore #programmingtutorials #programmingforbeginners #dotnetprogramming #programmingtutorials #learntocode #learnprogramming #learncsharp #sleaed #oops #Null-coalescing #null #Nullcoalescing #csharpoperators #nullcoalescingoperator

Useful links:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator

Code from the vide:
string nameOne = null;
string nameTwo = “Harry Potter”;

// 1. Basic Example
string nameTest = nameOne ??
nameTwo;
// 2. Chaining the operator
string nameTestTwo = nameOne ??
nameOne ??
“No Name Found”;
//3. Can also be used with methods
string nameTestThree = nameOne ??
GetAnotherName();

Comments are closed.