Hi/P>
One of the new features in the C# language is the support for nullable data types. If in your application you are dealing a lot with database having null fields and this will be very helpful although the nullable data types are useful in other situation also./P>
A data type that can contain defined data type or null value is nullable data type. Defing the nullable type is very simple. All we need to use is the ? modifier./P>
Normal declaration without nullable type/P>
Double d1=12;/o:p>/SPAN>/P> Declaration with nullable type./P> Double? D2= 12;/o:p>/SPAN>/P> Or/P> Double? D2= null;/o:p>/SPAN>/P> Nullable types are supposed to be used in the same way as we use regular value types. Infact we can also do implicit conversions between nullable and non nullable types of same type./P> Lets say we have 2 variable/P> Double? nFirst = null;/o:p>/SPAN>/A>/P> Double Second = 20000;/o:p>/SPAN>/SPAN>/P> /o:p>/SPAN>/SPAN>/P> nFirst = Second; /SPAN>/o:p>/SPAN>/SPAN>/P> nFirst = 12; /SPAN>/o:p>/SPAN>/SPAN>/P> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>All the above statements would be correct. /o:p>/SPAN>/SPAN>/PRE> nFirst = null; /SPAN>/o:p>/SPAN>/SPAN>/P>The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
Declaration with nullable type./P>
Double? D2= 12;/o:p>/SPAN>/P> Or/P> Double? D2= null;/o:p>/SPAN>/P> Nullable types are supposed to be used in the same way as we use regular value types. Infact we can also do implicit conversions between nullable and non nullable types of same type./P> Lets say we have 2 variable/P> Double? nFirst = null;/o:p>/SPAN>/A>/P> Double Second = 20000;/o:p>/SPAN>/SPAN>/P> /o:p>/SPAN>/SPAN>/P> nFirst = Second; /SPAN>/o:p>/SPAN>/SPAN>/P> nFirst = 12; /SPAN>/o:p>/SPAN>/SPAN>/P> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>All the above statements would be correct. /o:p>/SPAN>/SPAN>/PRE> nFirst = null; /SPAN>/o:p>/SPAN>/SPAN>/P>The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
Or/P>
Double? D2= null;/o:p>/SPAN>/P> Nullable types are supposed to be used in the same way as we use regular value types. Infact we can also do implicit conversions between nullable and non nullable types of same type./P> Lets say we have 2 variable/P> Double? nFirst = null;/o:p>/SPAN>/A>/P> Double Second = 20000;/o:p>/SPAN>/SPAN>/P> /o:p>/SPAN>/SPAN>/P> nFirst = Second; /SPAN>/o:p>/SPAN>/SPAN>/P> nFirst = 12; /SPAN>/o:p>/SPAN>/SPAN>/P> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>All the above statements would be correct. /o:p>/SPAN>/SPAN>/PRE> nFirst = null; /SPAN>/o:p>/SPAN>/SPAN>/P>The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
Nullable types are supposed to be used in the same way as we use regular value types. Infact we can also do implicit conversions between nullable and non nullable types of same type./P>
Lets say we have 2 variable/P>
Double? nFirst = null;/o:p>/SPAN>/A>/P> Double Second = 20000;/o:p>/SPAN>/SPAN>/P> /o:p>/SPAN>/SPAN>/P> nFirst = Second; /SPAN>/o:p>/SPAN>/SPAN>/P> nFirst = 12; /SPAN>/o:p>/SPAN>/SPAN>/P> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>All the above statements would be correct. /o:p>/SPAN>/SPAN>/PRE> nFirst = null; /SPAN>/o:p>/SPAN>/SPAN>/P>The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
Double Second = 20000;/o:p>/SPAN>/SPAN>/P> /o:p>/SPAN>/SPAN>/P> nFirst = Second; /SPAN>/o:p>/SPAN>/SPAN>/P> nFirst = 12; /SPAN>/o:p>/SPAN>/SPAN>/P> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>All the above statements would be correct. /o:p>/SPAN>/SPAN>/PRE> nFirst = null; /SPAN>/o:p>/SPAN>/SPAN>/P>The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
/o:p>/SPAN>/SPAN>/P> nFirst = Second; /SPAN>/o:p>/SPAN>/SPAN>/P> nFirst = 12; /SPAN>/o:p>/SPAN>/SPAN>/P> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>All the above statements would be correct. /o:p>/SPAN>/SPAN>/PRE> nFirst = null; /SPAN>/o:p>/SPAN>/SPAN>/P>The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
nFirst = Second; /SPAN>/o:p>/SPAN>/SPAN>/P> nFirst = 12; /SPAN>/o:p>/SPAN>/SPAN>/P> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>All the above statements would be correct. /o:p>/SPAN>/SPAN>/PRE> nFirst = null; /SPAN>/o:p>/SPAN>/SPAN>/P>The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
nFirst = 12; /SPAN>/o:p>/SPAN>/SPAN>/P> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>All the above statements would be correct. /o:p>/SPAN>/SPAN>/PRE> nFirst = null; /SPAN>/o:p>/SPAN>/SPAN>/P>The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>All the above statements would be correct. /o:p>/SPAN>/SPAN>/PRE> nFirst = null; /SPAN>/o:p>/SPAN>/SPAN>/P>The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
All the above statements would be correct. /o:p>/SPAN>/SPAN>/PRE> nFirst = null; /SPAN>/o:p>/SPAN>/SPAN>/P>The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
nFirst = null; /SPAN>/o:p>/SPAN>/SPAN>/P>The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
The above statement is also valid. But the below statement will give an exception since Second is not a nullable type./o:p>/SPAN>/SPAN>/PRE> Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
Second = nFirst; /SPAN>/o:p>/SPAN>/SPAN>/P>To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
To help avoid throwing an exception, we can use the nullable HasValue property to determine if the value is null or not./o:p>/SPAN>/SPAN>/PRE>Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
Hope this helps/o:p>Thanks/o:p>Vikram/o:p>/SPAN>/SPAN>/PRE>
This post explains very basic thing nicely. Can you provide the small example of this type in ado.net application as this is meant for used in database related application /p>
Good tip for beginners... /p>