What#39;s the deal with 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 是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:char.GetNumericValue 是怎么回事?


基础教程推荐
- 如何激活MC67中的红灯 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 XML 转换为通用列表 2022-01-01