Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How should I code this?
Message
 
 
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:
01399407
Views:
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.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform