Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# language feature
Message
De
04/09/2007 17:08:12
 
 
À
04/09/2007 04:06:39
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01252085
Message ID:
01252321
Vues:
17
> 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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform