char.GetNumericValue 是怎么回事?

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

问题描述

我正在研究 Project Euler 40,并且是有点困扰,没有 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 作为参数并返回...一个双精度值?
  • 如果 char 不是 '0' 到 '9',则返回 -1.0

那么这种方法背后的原因是什么,返回双重服务的目的是什么?我什至启动了 Reflector 并查看了 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 是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)