Skip to content

Instantly share code, notes, and snippets.

@Keboo
Last active September 20, 2020 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keboo/5950cdc6fa6f7395ee1482bfcb369241 to your computer and use it in GitHub Desktop.
Save Keboo/5950cdc6fa6f7395ee1482bfcb369241 to your computer and use it in GitHub Desktop.
Null constructor brain teaser. Simply replace ??? with any type that will cause the unit test to pass. Code used xUnit.
[Fact]
public static void NullReturnFromConstructor()
{
//Any Nullable<T> will work
Assert.Throws<InvalidOperationException>(() => SudoMakeMeSandwich<???>());
}
private static T SudoMakeMeSandwich<T>() where T : new()
{
return new T() ?? throw new InvalidOperationException();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment