Inline if else condition in c#

Its mostly use assign only one variable or object
Example: you have a variable and you want to check null value

int a = 100;
string result = string.Empty;
if (a < 20)
{
   result = "a variable less than 20";
}
else
{
   result = "a variable not less than 20";
}
you can use instead of old condition because its a major benefit to reduce line of code

int a = 100;
string result = a < 20 ? "a variable less than 20" : "a variable not less than 20";

Comments

Popular posts from this blog

Add Image through base64 on PDF in itextsharp

Set span value using jquery and javascript

how to insert text and tags at the cursor CKEDITOR