什么是char.GetNumericValue的处理? [英] What's the deal with char.GetNumericValue?
问题描述
我在 Project Euler 40 工作,是一个bit困扰,没有 int.Parse(char)
。不是什么大问题,但我做了一些问问,有人建议 char.GetNumericValue
。 GetNumericValue对我来说似乎是一个很奇怪的方法:
I was working on Project Euler 40, and was a bit bothered that there was no int.Parse(char)
. Not a big deal, but I did some asking around and someone suggested char.GetNumericValue
. GetNumericValue seems like a very odd method to me:
- 接受char作为参数并返回...? >
- 如果字符不是'0'到'9',则返回-1.0
这个方法背后有什么目的,返回双重服务?我甚至发射了反射器,看了看InternalGetNumericValue,但它就像看Lost:每个答案只是导致另一个问题。
So what's the reasoning behind this method, and what purpose does returning a double serve? I even fired up Reflector and looked at InternalGetNumericValue, but it's just like watching Lost: every answer just leads to another question.
推荐答案
记住,它采用Unicode字符并返回值。 '0'到'9'是标准的十进制数字,但是有其他的Unicode字符表示数字,其中一些是浮点型。
Remember that it's taking a Unicode character and returning a value. '0' through '9' are the standard decimal digits, however there are other Unicode characters that represent numbers, some of which are floating point.
Console.WriteLine( char.GetNumericValue( '¼' ) );
在控制台窗口中输出0.25。
Outputs 0.25 in the console window.
这篇关于什么是char.GetNumericValue的处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!