Nullable types in C# and VB.net
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
Visual basic.net
Dim i as Integer=Nothing '//Works but set i=0 Dim i as Integer?=Nothing '//Works set i=Nothing
C#
int i =null '//ERROR: type not nullable int? i =null '//Works set i=null
Leave a Reply
You must be logged in to post a comment.