Skip to content

Instantly share code, notes, and snippets.

@isidore

isidore/doifnull.cs

Last active Jul 30, 2016
Embed
What would you like to do?
string result = null;
result = result.DoIfNull(Win);
result = result.DoIfNull(Advantage);
result = result.DoIfNull(ScoreNormal);
result = result.DoIfNull(ScorePerson1);
result = result.DoIfNull(ScorePerson2);
result = result.DoIfNull(ScoreTie);
return result;
public static T DoIfNull<T>(this T t, Func<T> f )
{
if (t == null)
{
return f();
}
return t;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment