Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

? in c#

// Null-conditional operators ?. and ?[]
// Available in C# 6 and later: basically means:
Evaluate the first operand; if that's null, stop, with a result of null.
Otherwise, evaluate the second operand (as a member access of the first operand)."

//example:
if (Model.Model2 == null
  || Model.Model2.Model3 == null
  || Model.Model2.Model3.Name == null
{ mapped.Name = "N/A"}
else { mapped.Name = Model.Model2.Model3.Name; }}
    
// can be simplified to 
mapped.Name = Model.Model2?.Model3?.Name ?? "N/A";
Comment

PREVIOUS NEXT
Code Example
Csharp :: raycasting in unity 
Csharp :: c# clamp 
Csharp :: how to convert date to Complete ISO-8601 date in c# 
Csharp :: {"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."} 
Csharp :: c# input 
Csharp :: convert string to number c# 
Csharp :: ef core set identity_insert off 
Csharp :: html beginform 
Csharp :: difference between class and struct in c# 
Csharp :: c# best tutorial 
Csharp :: unity c# get direction of object 
Csharp :: c# nullable string 
Csharp :: C# how to use if and else 
Csharp :: c# remove first line from textbox 
Csharp :: build cs file 
Csharp :: Convert DataTable to Dictionary in C# 
Csharp :: 2d list c# 
Csharp :: unity find gameobject with layer 
Csharp :: C# Http.HttpRequestMessage 
Csharp :: unity setparent 
Csharp :: convert object to httpcontent c# 
Csharp :: speedtest.net cli 
Csharp :: c# round number up 
Csharp :: c# get list item in random order 
Csharp :: how to check if the value is alphabet and numbers only only in c# 
Csharp :: how to read a text file C# 
Csharp :: how get the user show mvc controller core 3.1 
Csharp :: c# how to print 
Csharp :: what is unity 
Csharp :: wpf textblock line break code behind 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =