Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How should I code this?
Message
De
15/05/2009 12:12:01
 
 
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:
01400152
Vues:
69
>>>>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.

Didn't know that. In that case you'd have to rely on Convert and add more error checking....
Maybe it would be a good idea for UT to have a .NET CE section - I sometimes forget you're working with CE....
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform