char.GetNumericValue 是怎么回事?

3

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

问题描述

限时送ChatGPT账号..

我正在研究 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 是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14

函数委托与函数
Func Delegate vs Function(函数委托与函数)...
2023-11-11 C#/.NET开发问题
6

具有未知类型的 CreateDelegate
CreateDelegate with unknown types(具有未知类型的 CreateDelegate)...
2023-11-11 C#/.NET开发问题
5