Convert char to int in C#

后端 未结 14 1165
情深已故
情深已故 2020-11-22 10:44

I have a char in c#:

char foo = \'2\';

Now I want to get the 2 into an int. I find that Convert.ToInt32 returns the actual decimal value o

14条回答
  •  无人共我
    2020-11-22 11:14

    Interesting answers but the docs say differently:

    Use the GetNumericValue methods to convert a Char object that represents a number to a numeric value type. Use Parse and TryParse to convert a character in a string into a Char object. Use ToString to convert a Char object to a String object.

    http://msdn.microsoft.com/en-us/library/system.char.aspx

提交回复
热议问题