我如何使用在C#枚举一个特殊字符? [英] How can I use a special char in a C# enum?

查看:1257
本文介绍了我如何使用在C#枚举一个特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

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.

这篇关于我如何使用在C#枚举一个特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆