In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "C # enumeration and enumeration members how to use", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "C # enumeration and enumeration members how to use" it!
The C # enumeration type is a value type that declares a set of named constants.
(1) declaration of the C# enumeration: the enumeration declaration is used to declare a new enumeration type.
Access rhetoric enum enumerated name: base type {C # enumeration member}
The underlying type must be able to represent all enumeration values defined in the enumeration. Enumeration declarations can explicitly declare byte, sbyte, short, ushort, int, uint, long, or ulong types as corresponding base types. An enumeration declaration that does not explicitly declare the underlying type means that the corresponding underlying type is int.
(2) C # enumeration members
Enumeration members are named constants for this enumeration type. Any two enumeration members cannot have the same name. Each enumeration member has an associated constant value. The type of this value is the base type of the enumeration. The constant value of each enumeration member must be within the range of the underlying type of the enumeration.
Example of C# enumeration members:
Public enum TimeofDay:uint {Morning=-3, Afternoon=-2, Evening=-1}
A compile-time error occurs because the constant values-1,-2, and-3 are not within the range of the underlying integer uint.
(3) default values of C# enumeration members
The default value of the * enumerated members declared in the enumerated type is zero.
Subsequent enumeration member values are obtained by adding 1 to the value of the previous enumeration member (in text order). The increased value must be within the range of values that can be represented by the underlying type; otherwise, a compile-time error will occur.
Example of C# enumeration members:
Public enum TimeofDay:uint {Morning, Afternoon, Evening}
The value of Morning is 0, the value of aftertaste is 1, and the value of Morning is 2.
(4) display assignments for C# enumeration members
Multiple enumeration members are allowed to have the same value.
The value of the assigned enumeration member is not displayed, and the value of the previous enumeration member is always + 1.
C # enumeration member example
Public enum Number {axi1, b, cyste1, d}
The value of b is 2 and the value of d is 2.
Note: none of the above C # enumeration values can exceed its base type range. Otherwise, an error will be reported.
Thank you for your reading, the above is the content of "how to use C# enumerations and enumeration members". After the study of this article, I believe you have a deeper understanding of how C# enumerations and enumeration members are used. the specific use also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.