Nullable types in C# and

Have you ever try to assign null to int value in C# or VB

Both language has totally different behavior. VB allows you assign Nothing but it will translate to zero on the other end C# throws error “type is not nullable”

Here is how you can set Integer to Null value in Both languages


Dim i as Integer=Nothing  '//Works but set i=0
Dim i as Integer?=Nothing  '//Works set i=Nothing


int i =null '//ERROR: type not nullable
int? i =null '//Works set i=null

Binary World is a Software Development company located in Atlanta, USA (since 2007). Binary World specialized in Business Intelligence, mobile, cloud computing and .Net Application Development.

Posted in .net, C#, Tips,

Leave a Reply