Thursday, September 23, 2010

Of c # (11) enumeration (Enums)


1.11 enumeration (Enums)

Enumerates a set of attributes declared as the same constant names define a single category. It is commonly used in some of the known range at compile time constants. However, the specific values of these constants to be determined at execution time. For example, the known blue and green primary colors are red, they belong to the same color. Can be defined as follows:

backup / bin / bin_old / conf / data / eshow / log / maint / news: 10 / news: 11 / news: 12 / news: 13 / news: 14 / news: 15 / news: 16 / news: 17 / news: 18 / news: 2 / news: 3 / news: 4 / news: 5 / news: 6 / news: 7 / news: 8 / news: 9 / seeds / svn / tasks / tmp / xml2dict-read-only /
enum Color (
Red,
Blue,
Green
)
/ Bin / boot / dev / etc / home / lib / lost + found / media / misc / mnt / net / opt / proc / root / sbin / selinux / srv / sys / tmp / u01 / usr / var / vmware

We create a shape (form) class, every body will have color. Colors are "shape" of the property. However, the implementation of the specific color must be decision time:

backup / bin / bin_old / conf / data / eshow / log / maint / news: 10 / news: 11 / news: 12 / news: 13 / news: 14 / news: 15 / news: 16 / news: 17 / news: 18 / news: 2 / news: 3 / news: 4 / news: 5 / news: 6 / news: 7 / news: 8 / news: 9 / seeds / svn / tasks / tmp / xml2dict-read-only /
class Shape
(
public void Fill (Color color) (
switch (color) (
case Color.Red:
...
break;
case Color.Blue:
...
break;
case Color.Green:
...
break;
default:
break;
)
)
)
/ Bin / boot / dev / etc / home / lib / lost + found / media / misc / mnt / net / opt / proc / root / sbin / selinux / srv / sys / tmp / u01 / usr / var / vmware

The File method to illustrate how a kind of a given color to give shape class. Enumeration better than ordinary integer constant lies: it makes the code easier to read to understand and more secure. Enumeration constants can be decided by the compiler. Use the compiler can also check its validity. C # enumeration is not unique. Hey, I do not woven detail. Took the opportunity to shoot! If anyone interested - his reading! (To avoid eating too many bananas would introduce the book "c language programming FAQ" Tsinghua 1996. 29.00 yuan. Although ancient, I can see in the bookstore)






Recommended links:



Striving to be China's "Shipbuilding City", on the shipbuilding industry along the Yangtze River



ASF to MOV



Compare Casino And Gambling



Haoxiliantai ABPlayer experience high-definition player 2.6



Accelerator With The PP To See Potatoes, No Buffer Youku



M2TS Converter



MPG to 3GP



Computer Fraud, Although He Is Alleged To Have Bought



The other side of performance evaluation [1]



System Utilities comments



RFID into THE competition for the critical period



Fireworks 8 dream trip (9): production of POP-UP menu



Customer Is Not His Wife Is A Lover Of God Is



free visual style



No comments:

Post a Comment