Josh-CO Dev

Solving the worlds problems one line of code at a time.

C# Nullable datatypes – How to set a variable to accept nulls

Leave a comment

This is a nifty little trick that I almost forgot about until today. Often times you need to pass a null value into a non-nullable datatype, such as an int. If you don’t know a trick, this can be pretty difficult. Here’s the trick:

int? varName;

Simple eh? Just add a question mark to the end of the datatype. This will force it to become a nullable datatype.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s