Exploring Nullable types : Part 2

This is second and last part of the post on Nullable type series. You can view the first part from here

Exploring Nullable types : Part 1

In this series, I will talking certain rules that we need to take care while using Nullable type. I will be taking scenario wise.

First scenario:

Int? a=8;
object o = a;
long d = (long)c;

It will be compiled successfully but will throw and Invalid Cast Exception. Means, you cannot cast it to any other type except the underlying type which is here int although  int type can be hold by long.

Continue reading

Advertisement

Exploring Nullable types : Part 1

In this post, I am going to talk about Nullable types. Actually most of developers know, in c# we have
mainly two types.
– Reference type
– Value type.
But we have more type, that is called Nullable type.

Actually it is a value type but it has feature of both reference and Value type.

Continue reading