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 是怎么回事?
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
