在c#中有类似java的Character.digit(char ch,int radix)吗? [英] Is there something like java's Character.digit(char ch, int radix) in c#?
本文介绍了在c#中有类似java的Character.digit(char ch,int radix)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Character.digit(char ch, int radix)
返回指定基数中字符ch的数值。
Returns the numeric value of the character ch in the specified radix.
c#中是否有等效函数?
Is there an equivalent function in c#?
推荐答案
我不知道直接等价物
我能找到的最接近的匹配是
I don't know of a direct equivalent
The closest match I can find is
Convert.ToInt32(string s, int baseFrom);
所以你可以将你的char转换为string然后将它传递给上面的函数来获取int32或者Int16或Byte或者你想要处理它:
So you could convert your char to string then pass it in to the above function to get the int32 or Int16 or Byte or however you want to handle it :
char c = 'F';
int digit = Convert.ToInt32(c.ToString(),16);
注意 - 如果char不是数字,转换将抛出FormatException
Note - Convert will throw a FormatException if the char isn't a digit
这篇关于在c#中有类似java的Character.digit(char ch,int radix)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文