C# Wishlist: Non-nullable Reference Types

When I started my C# Wishlist series, one wish, though never published, was to introduce non-nullable reference types in C#.

Everybody who has written the lines

public class C
  public C (T somearg)
    if (somearg == null)
      throw new NullArgumentException("somearg");

several thousand times would appreciate this language feature. (as Yann’s comment on a Jon Skeet blog post illustrates)

Now, a couple of years later, Eric Lippert read my mind, and answers why the (consistent!) implementation of this feature is not as trivial as it sounds.

Workaround for the time being: Code Contracts (.Net 4 and above) or external libraries such as CuttingEdge.Conditions.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: