Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How should I code this?
Message
 
 
À
11/05/2009 03:12:34
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01398722
Message ID:
01399407
Vues:
70
>>>Hi,
>>>If Naomi has access to the biz layer source then, yes I'd agree, a better solution.
>>>An alternative with wider use might be to add a .ToNullableInt() extension method for String.
>>>Best,
>>>Viv
>>>
>>I do have an access to BL, so I may code it there. For the extension method I haven't done them yet, so I'm not sure how to implement it.
>
>The Extension method would be something like:
public static int? ToNullableInt(this string s)
>{
>    int result;
>    bool b = Int32.TryParse(s,out result);
>    return b ? (int?) result : null;
>}
Then anywhere this method is in scope you could use, for example:
string s = "12345";
>int? i = s.ToNullableInt();
Note the above implementation would return null for any string that doesn't translate to a valid int (null, string.empty, "123.45", "asd" etc.) which may no be exactly what you want. And I wouldn't bother to implement this unless you know it will have a wider use than in your original requirement....
>Best,
>Viv

Viv,

Int32 doesn't have TryParse method in .NET CE.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform