Help with C # - How to check what kind of variable? HWzone Forums
adplus-dvertising
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?


Unonymous
 Share

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

Link to content
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';

 

Link to content
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!

Link to content
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.

 Share

×
  • Create new ...

At the top of the news:

new on the site