本文介绍了一个C#枚举项可以在名称的连字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时THRE没有办法有一个连字符枚举项, - ,在名称,例如:

 枚举myEnum 
{
OK,
不-OK,
}

我见过的关于有友好的名字会救我一些工作,如果我可以直接使用连字符



更新:我想用连字符的原因是它使它易于使用一个枚举的,我有过,如不控制设定值列表:

 拒绝
代替
本地再见
远程再见


解决方案

没有,连字符是不允许的。





您可以明显替换用下划线连字符,但作为@benPearce建议,驼峰会是一个更好的选择,并与大多数C#编码标准。


Is thre any way to have an enum entry with a hyphen, "-", in the name, for example:

enum myEnum
{
   ok,
   not-ok,
}

I've seen the question about enums having friendly names however it would save me a bit of work if I can use a hyphen directly.

Update: The reason I want to use a hyphen is it makes it easy to use an enum for lists of set values which I have no control over such as:

 rejected
 replaced
 local-bye
 remote-bye
解决方案

No, a hyphen is not allowed.

Identifiers

You could obviously replace the hyphen with an underscore, but as @benPearce suggested, CamelCase would be a better choice, and in line with most C# coding standards.

这篇关于一个C#枚举项可以在名称的连字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 12:02