Re: Import Microsoft.VisualBasic for IsNumeric?
- From: "Lau Lei Cheong" <leu_lc@xxxxxxxxxxxx>
- Date: Tue, 17 Jan 2006 09:56:23 +0800
I see.
But... for the purpose of assignment to a variable, I think checking to see
if it can be successfully assigned to a variable of that variable type is
good enough. Isn't it?
"Peter Bromberg [C# MVP]" <pbromberg@xxxxxxxxxxxxxxxxxxx> ¼¶¼g©ó¶l¥ó·s»D:F14A2C73-EC66-4241-B99D-927DB8676B41@xxxxxxxxxxxxxxxx
> The IsNumeric method from Microsoft.VisualBasic is not that simple. It
> does
> an incredible amount of complex type-checking with culture, Iconvertible,
> etc. under the hood.
>
> However, if you want a C# "Simplistic" version, I'd suggest using
> double.TryParse, which does not throw an exception.
> Peter
>
>
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "Lau Lei Cheong" wrote:
>
>> After you imported Microsoft.VisualBasic namespace, when you type
>> "IsNumeric(", does the Intellisense show up?
>>
>> And I wish to ask another question. For the OP's purpose, he can use the
>> IsNumeric() function from Microsoft.VisualBasic namespace, or attempt to
>> write one for himself with the following:
>>
>> public static bool InNumeric(string inputstr)
>> {
>> bool result = false;
>> try
>> {
>> decimal temp = Convert.ToDecimal(inputstr);
>> result = true;
>> }
>> catch
>> {
>> result = false;
>> }
>> return result;
>> }
>>
>> Of course he may also determine the result by comparing the ASCII values
>> of
>> the string one by one for "0"-"9" and "." (possibly "e" and so on if
>> applicable)
>>
>> For the above methods, which one is recommended to do in C#?
>>
>> "Dave" <Dave@xxxxxxxxxxxxxxxxxxxxxxxxx> ???gco?l¢Do¡Ps?D:5B6308E2-F4F4-4EF6-B0E0-74E337ABC359@xxxxxxxxxxxxxxxx
>>
>> > I'm trying to import Microsoft.VisualBasic to use the IsNumeric
>> > function
>> > in
>> > my C# code but all I see is:
>> >
>> > Microsoft.VisualBasic.VBCodeProvider while using Intellisense...
>> >
>> > From samples shouldn't I see
>> > Microsoft.VisualBasic.Information.IsNumeric?
>> >
>> > Thanks
>>
>>
>>
.
- References:
- Re: Import Microsoft.VisualBasic for IsNumeric?
- From: Lau Lei Cheong
- Re: Import Microsoft.VisualBasic for IsNumeric?
- Prev by Date: Re: Custom validator
- Next by Date: Re: where to set the current culture in ASP.NET 2.0?
- Previous by thread: Re: Import Microsoft.VisualBasic for IsNumeric?
- Next by thread: Re: Content Pages
- Index(es):
Relevant Pages
|