user2925656 user2925656 - 5 months ago 43
C# Question

Avoid nested if for null and parameter condition

Is it possible to avoid nested if statements while I want to check if variable/object is null and if variable/object meet some condition eg.

var obj = "test";
do something;

Is it possible to do oneliner of this statement without defining own method which handle this ?


You can also try (in Java)


this way, you don't have to do an explicit null check,