如何在Enum中写入值时使用/或 - ? [英] How to use / or - while writing values in Enum ?

查看:67
本文介绍了如何在Enum中写入值时使用/或 - ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Enum。

Enum abs
{
  yy=1,
yy/yy=2
}



这种方式我想定义并想在radiobutton列表中显示这种方式当我将我的列表绑定到此枚举。



但是在编写Enum时,它在我使用/时给出了错误。请建议。


This way i want to define and want to display in radiobutton list this way when i bind my list to this Enum.

But at the time of writing Enum,its giving me error when i use / . Please suggest.

推荐答案

你可以使用带枚举的DisplayName属性。



下面 - 不太现实示例,但你可以考虑的事情。

You can use DisplayName attribute with the enum.

Below - not a realistic example but something that you could consider.
public enum Name{
  [DisplayName("FN")] FirstName,
  [DisplayName("%LN")] LastName
}


您正在为变量/常量/枚举项使用禁用字符。你无法使用那个角色。您可以改为使用_。



您的商品不能以数字开头,也不能在任何地方使用%&/ + - *。



谷歌保留字符了解更多信息。



此外,我不确定你应该为你的枚举增值这些项目通常从0开始编号。
You are using forbidden character for variable/constant/enum items. No way you can use that character. You can use "_" instead.

Your item cannot begin with a number, nor use % & / + - * anywhere.

Google "reserved characters" for more info.

Also, I'm not sure you are supposed to giva a value to your enumeration items, they usually number themselves starting at 0.


这篇关于如何在Enum中写入值时使用/或 - ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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