c# - .NET 中定义的 char struct -- 运算符在哪里?

标签 c# .net

当我查看 .NET Char Struct 的文档(此处: https://docs.microsoft.com/en-us/dotnet/api/system.char )时,我可以看到常用的属性、方法等,就像 .NET Framework 中定义的任何其他类型一样。

我知道 char 结构有一个 --为它定义的运算符,因为我可以执行以下操作:

char current = 'b';
current--;   // current now holds the value a.

在查看 Microsoft 文档时,我希望看到一个运算符重载定义,它看起来像:
public static Char operator --(char character)
{
}

问题是我没有看到类似的东西,也没有说哪个运算符为该类型重载。对于 char Type 示例,char 有一个运算符重载 for -- 但不是 for -,我认为最好知道所有重载运算符的记录位置,而不是进行试验和错误。

所以我的问题是:如何知道为哪种类型定义了哪个运算符?我错过了 .NET API 文档中的其他地方吗?

最佳答案

您正在寻找的内容在 C# Language Specification 中有所描述。 .
Integral Types主题将 char 类型列为整数类型之一。

The char type represents unsigned 16-bit integers with values between 0 and 65535. The set of possible values for the char type corresponds to the Unicode character set. Although char has the same representation as ushort, not all operations permitted on one type are permitted on the other.



关于运营商你需要看Prefix increment and decrement operators C# 语言规范中的主题。

Predefined ++ and -- operators exist for the following types: sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, and any enum type.

关于c# - .NET 中定义的 char struct -- 运算符在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61668344/

相关文章:

c# - 我如何以编程方式(使用反射?)更改方法体并将我的更改保存回磁盘

c# - 在多个配置文件中重新定义 spring.net 对象

c# - ASP.NET Core 依赖解析器

.net - 需要一个从 Midi 生成 WAVE 的库

c# - FluentValidation 和 Entity Framework 查找

c# - 在 C# 应用程序中使用 b-pac SDK 进行标签打印开发

c# - 将根 JSON 数组映射到类型的属性。 。网

c# - 依赖注入(inject)的 Xamarin iOS Controller 自定义继承问题

c# - CSVHelper:使用 IndexAttribute 写出一个空字段

c# - 一般异常处理问题