Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How should I code this?
Message
From
15/05/2009 12:12:01
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01398722
Message ID:
01400152
Views:
68
>>>>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....
Previous
Reply
Map
View

Click here to load this message in the networking platform