Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# language feature
Message
From
04/09/2007 17:08:12
Walter Nicholls
Cornerstone Software Ltd
Auckland, New Zealand
 
 
To
04/09/2007 04:06:39
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01252085
Message ID:
01252321
Views:
19
> double?

Also another couple of tips - if you want to assign a "double?" to a "double" you need to cast it, which may seem odd .. and if the value is null, you'll get an exception doing such a cast ... leading perhaps to code like this:
//function being called is defined as void DoSomething( double x )
double? myValue;
if( null !=  myValue )
{
   DoSomething( (double)myValue );
}
If you have a nullable value type like double? or int?, and want nulls to become a value in the equivalent non-nullable type, there is a shorthand you may come across:
double? myNullableValue; double myNonnullValue;
myNonnullValue = myNullableValue ?? 0;
// is equivalent to:
myNonnullValue = (myNullableValue!=null) ? (double)myNullableValue : 0;
// which is of course equivalent to
if(myNullableValue!=null) { myNonnullValue = (double)myNullableValue; }
else { myNonnullValue = 0; }
I wish the ?? syntax worked with strings, eg sValue??"None", but strings are objects, and it doesn't.

Walter
Previous
Reply
Map
View

Click here to load this message in the networking platform