3
Reply

What is Nullable values types?

    Simply nullable value type have ability to store null value. To declare a nullable value type we need to suffix the type name with "?"Eg-string str=null; //Valid int p=null; //Invalid int? p=null; //Valid

    As we know that, the value type has default value as 0 and reference type has default value as NULL. the convention is that, we cannot assign NULL to value types. But, while working with the databases, it might be have NULL values, because in databases, it is allowed. So, to do this, we have to explicitly assign the NULL values to the Value Types. this can be done by suffixing the ? sign to the type as:- int? i = NULL; then the value type int i will store the NULL value. this is called as Nullable Value Types.

    In earlier versions of c# it is not possible to store null values under value types(eg int, float, char...). But in c# 2.0 it is possible to store null values under value types also which gives you more flexibility while communicating with database.To declare a nullable value type we need to suffix the type name with "?"Eg-string str=null; //Valid int p=null; //Invalid int? p=null; //Valid