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

问题描述

  enum myEnum 
{
ok,
not-ok,
}

我看到有关,但是如果我可以直接使用连字号,那么它会节省一些工作。



更新:我想使用连字符的原因是它对于我无法控制的设定值列表,可以轻松使用枚举:

 已拒绝

local-bye
remote-bye


解决方案

不,连字符是不允许的。





你可以用下划线替换连字符,但是@benPearce建议,CamelCase将是一个更好的选择,符合大多数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