C# - 都是枚举常数? [英] C# - are all Enum constants?

查看:121
本文介绍了C# - 都是枚举常数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有枚举枚举都是常量吗?

解决方案

在编译时,他们是不变的是的,编译时间。



参考:
http://msdn.microsoft.com/en-us/library/sbbt4032.aspx



从介绍: / p>


枚举关键字用于声明
一个枚举,一个独特的类型,
由一组命名常量
调用枚举器列表。


在鲁棒编程下:


正如任何常量一样,
的个人值的所有
引用都将转换为数字
文字在编译时
。这可以
在常量(C#Programming
Guide)中描述的
创建潜在的版本控制问题。



Are all Enum enumerations constants? Do they get converted to their value at compile-time, or at run-time?

解决方案

They are constant. Yes, compile time.

Reference: http://msdn.microsoft.com/en-us/library/sbbt4032.aspx

From the intro:

The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list.

Under "Robust Programming":

Just as with any constant, all references to the individual values of an enum are converted to numeric literals at compile time. This can create potential versioning issues as described in Constants (C# Programming Guide).

这篇关于C# - 都是枚举常数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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