Help with C # - How to check what kind of variable? HWzone Forums
Skip to content
  • Create an account
  • About Us

    Hello Guest!

     
    Please note - in order to participate in our community, comment and open new discussions, you must join as a registered member.

    Our members enjoy many advantages, including the ability to participate in discussions, enjoy raffles and promotions for members of the site, and receive our weekly content directly by email.

    Do not like being harassed by email? You can register for the site but do not submit your registration to the weekly email updates.

Help with C # - How to check what kind of variable?


Recommended Posts

Hi, I have a section in the program that I get from the user some value and I put this value into a string but it should be some number, how can I check if that value is a number? 

I would really love if someone could help me with that !! Thank you

Post Reply Direct Link To This Post
Share on other sites

Two comments:

A. A more idiotic way to pass a character character is on a foreach loop:

foreach (tank ch in str)
{
  bool b = tank.IsDigit(ch);
}

Or of course LINQ if you studied.

B. char.IsDigit checks if the character is a Unicode digit, so the character גם (code U + ABF6) Will return true (it's 6 in some variant of Indian).

If this is not desirable, you can check for ASCII only:

bool IsDigit(tank ch) => '0' <= ch && ch <= '9';

 

Post Reply Direct Link To This Post
Share on other sites
Quote by af db creid

Two comments:

A. A more idiotic way to pass a character character is on a foreach loop:

foreach (tank ch in str)
{
  bool b = tank.IsDigit(ch);
}

 

I never remember the foreach syntax by heart, I preferred to write from memory a code that will run safely (rather than open a VS that will complete me automatically :)) ....

Quote by af db creid

 

Of course LINQ if you studied.

 

 

According to the question, it seems that not yet ....

Quote by af db creid

 

B. char.IsDigit checks if the character is a Unicode digit, so the character גם (code U + ABF6) Will return true (it's 6 in some variant of Indian).

 

Thanks

New to me!

Post Reply Direct Link To This Post
Share on other sites

Join the discussion

You can then join the discussion and then join our community. If you already have an account with us, please Log in now To comment under your username.
Note that: The comment will appear to the surfers after approval by the board management team.

guest
Add a comment

×   The content pasted is with formatting.   Remove formatting

  Only 75 emoji are allowed.

×   Your link has been automatically assimilated.   Show as regular link

×   Your previous content has been automatically restored.   Clear all

×   You can not paste images directly. Upload or insert images from URL.

  • Latest news

  • Buzz-Zone: Everything hot on the net

  • Popular now

×
  • Create new ...

At the top of the news:

In June everything will work out? The MWC 2021 exhibition begins with a Corona-adapted version

Instead of a grandiose mobile celebration in Barcelona - we get a relatively small event in Shanghai this week, and plans for a European comeback this coming June The MWC (Mobile World Congress) was the first notable technological event to suffer last year's coronation, with naive restrictions in the first stage, Complete cancellation of the physical event afterwards - and at the same time promises that next year everything will return to normal, when it is likely that at that point in time no one guessed or predicted that even in 2021 ...

new on the site