Trying to write code in one line

4/1/2014·1 min read

For example, if you have following method, passing string[], there're few way to handlering it.

public void CheckCondition(string[] values)

{
if (values == null)
{
return "value is null.";
}
else
{
return "value is not null";
}
}

 

public string CheckCondition(int? value)

{
if (value == null)
{
return "value is null.";
}
else
{
return "value is not null";
}
}

 

C# -- use (??) to check NULL value

public string CheckCondition(int[] values)

{
var t = values ?? "value is null."
}

 

It'll be cool to use (??), since it's kind of cool to make two question mark(??). But I'd rather use if else. If Microsoft could prove something like (?? :), which is "if it's null(??) do this, else do others.

Operators ?? also can't be overloaded. So, if you want to try something like How to OverLoading Operator.This. Which you can't do it for (??).