Friday, May 20, 2011

What is Nullable Numeric DataType?

Defination: Nullable DataTypes are the Types Which can hold Null Value e.g Int, Decimal, Float ,long, bool
Why Required?
Many times we are not confirmed that coming values are Null or Proper.
e.g If Table colm is allowed null and its Type is Int in that case assignment of data into int Type will
be fail (int=Null)
Syntex: Type + ? e.g int?,bool?,long? etc
Nullable Numeric DataTypes e.g Float ,Int, long,Decimal
int? _nullableName;
int _name1;
_nullableName = null;
_name1 = (int)_nullableName;
Console.WriteLine(_name1.ToString());
//Note: If Nullable DataType is having Null value and we are assinging it to some Not Nullable type ,it will throw exception
int standardInteger = 123;
int?
nullableInteger;
decimal standardDecimal = 12.34M;
// Implicit conversion from int to int?
nullableInteger =
standardInteger;
// Explicit conversion from int? to int
standardInteger = (int)
nullableInteger;
// Explicit cast from decimal to int?
nullableInteger = (int?)standardDecimal;

No comments: