Such as i have declared,
double x;
now i want to assign
x=NULL how can i do this ? I have seen some other answers of it but couldn't understand them, that's why opening this thread .
You have to declare it as a nullable type:
double? x;
x = null;
Non nullable types like double can not be null
You cant assign null to a non-nullable type
You can use NaN
(not a number) for a non-nullable double
double x;
x = double.NaN;
Nullable types are instances of the System.Nullable(Of T) struct. A nullable type can represent the correct range of values for its underlying value type, plus an additional null value. For example, a Nullable, pronounced "Nullable of Int32," can be assigned any value from -2147483648 to 2147483647, or it can be assigned the null value. A Nullable can be assigned the values true false, or null. The ability to assign null to numeric and Boolean types is especially useful when you are dealing with databases and other data types that contain elements that may not be assigned a value. For example, a Boolean field in a database can store the values true or false, or it may be undefined.
double? amount = null;
http://msdn.microsoft.com/en-us/library/vstudio/2cf62fcy.aspx
Possible Duplicates:
Why can't I set a nullable int to null in a ternary if statement?
Nullable types and the ternary operator: why is `? 10 : null` forbidden?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With