我如何使用在C#枚举一个特殊字符?如何使用、特殊字符

2023-09-02 10:51:28 作者:孤帆去悠悠

例如:

public enum Unit{
  KW,
  kV,
  V,
  Hz,
  %V
}

在这种情况下,%是一个特殊字符。所以,我怎么可以把这个字符在枚举?

In this case % is a special character. So, how can I put this char in a enum?

推荐答案

枚举成员不应该被用于用户界面显示的目的。它们应该被映射到的字符串以得到显示。您可以创建一个字符串数组(或字典),每个枚举成员映射到一个字符串与用户交互。

Enum members shouldn't be used for user interface display purposes. They should be mapped to a string in order to get displayed. You can create a string array (or a dictionary) that maps each enum member to a string for user interaction.

也就是说,可以直接回答你的问题,你可以使用 uxxxxV XXXX 是十六进制数再presenting的统一code $ C $下点。这是远远建议。作为亨克指出,这不会对工作,因为它不是在统一code类鲁,LL,中尉,LM,罗,NL,锰,三菱商事,钕,PC,CF(字母,数字,连接和格式字符)。只有这些字符是可接受的标识符

That said, to answer your question directly, you can use uxxxxV were xxxx is the hexadecimal number representing the Unicode code point for %. This is far from recommended. As Henk points out, this won't work for % as it's not in Unicode classes Lu, Ll, Lt, Lm, Lo, Nl, Mn, Mc, Nd, Pc, Cf (letters, digits, connecting, and formatting characters). Only these characters are acceptable for identifiers.

 
精彩推荐
图片推荐