本文介绍了这是怎么回事与char.GetNumericValue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的项目欧拉40 ,并有点麻烦,有没有 int.Parse(字符)。没什么大不了的,但我做了一些四处询问,有人建议 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:

  • 在一个字符作为一个参数,并返回......双?
  • 返回-1.0如果字符不是0到9

那么,什么是这种方法背后的原因,和什么目的不返回一个双服务?我甚至发射了反射,看着InternalGetNumericValue,但它只是喜欢看失落:每一个答案只是导致了另一个问题

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.

推荐答案

请记住,它采取了统一code字符并返回一个值。 '0'到'9'是标准的十进制数字,但也有一些重新present号码,其中一些是浮点其他的Uni code的字符。

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 20:29