C # Idioms:enum or enum class (enum Class)
Marshine
(Original composition format: http://www.marshine.com)
Reversion:2004/5/28
Modification Note: Thanks to the CLS compatibility issue mentioned by Ninputer, while modifying the Equals rewrite not
Q: In C #, how do we express enumeration types?
A: You can use the enum keyword (keyword) to declare an enumeration type (enum type ):
// Code #01
public enum Alignment
{
Left,
Center,
Right
}
------------
In the long run, creating enumeration can save a lot of time and reduce a lot of trouble. Enumeration has at least three advantages over unformatted integers:
● Enumeration makes the code easier to maintain and helps to specify valid and expected
C # convert enum to string for Enumeration type conversion
All enumeration types are value types.
System. enum is an abstract class. All enumeration types inherit from it directly, and of course all its members.
All value types are system. the
PHP low-level programming Brothers to look at this problem, I make the following statement, I hope to be able to objectively understand the advantages and disadvantages of this enum field:
Fat brother Point of view:An enum has advantages. But
C # enum,int,string conversion [goto]C # enum,int,string The reciprocal conversion enum provides a base class for enumerations whose underlying type can be any integral type except Char. If you do not explicitly declare an underlying type, use Int32.
If a variable requires several possible values, it can be defined as an enumeration type. The reason for enumeration is to enumerate the possible values of variables or objects.
For example, to make everyone better understand that there is a pen in
Enumeration
The enumerated type Declaration defines a type name for a group of related symbol constants. Enumeration is used for "Multiple Choices", that isProgramThe runtime is determined by the fixed number of "Choices" that have been set at the
Original article: c # enum usage enumeration usage Asp.net ENUM usage
The enum keyword is used to declare enumeration, which is a unique type consisting of a group of named constants called the enumeration list. Each Enumeration type has a base type,
In the development process, some state representation is used to the enumeration type, so how to bind the enum type directly to ListControl (DropDownList) is the subject of this time, the nonsense is not much to say, the direct code:First look at
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.