Answers for "check value before assigning using ternary operator"

C#
0

check value before assigning using ternary operator

// you can use below method to reduce null value exceptions while assigning value to variables 
// check if value is available then assign value else asisgn default/empty value
if (mystring != null)
{
	AnotherStringVarialble = mystring;
}
else
{
	AnotherStringVarialble = String.Empty;
}

//or you can use below code instead 

AnotherStringVarialble = (mystring != null) ? mystring : String.Empty ;
Posted by: Guest on August-05-2021

C# Answers by Framework

Browse Popular Code Answers by Language