C# 0 The Complete Reference


PART I C h a p t e r   1 2



Download 4,07 Mb.
Pdf ko'rish
bet429/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   425   426   427   428   429   430   431   432   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART I

C h a p t e r   1 2 :  

I n t e r f a c e s ,   S t r u c t u r e s ,   a n d   E n u m e r a t i o n s  

333


PART IPART I

      "Red",

      "Red",

      "Red",

      "Reddish Green"

    };


    Apple i; // declare an enum variable

    // Use i to cycle through the enum.

    for(i = Apple.Jonathan; i <= Apple.McIntosh; i++)

      Console.WriteLine(i + " has value of " + (int)i);

    Console.WriteLine();

    // Use an enumeration to index an array.

    for(i = Apple.Jonathan; i <= Apple.McIntosh; i++)

      Console.WriteLine("Color of " + i + " is " +

                         color[(int)i]);

  }


}

The output from the program is shown here:

Jonathan has value of 0

GoldenDel has value of 1

RedDel has value of 2

Winesap has value of 3

Cortland has value of 4

McIntosh has value of 5

Color of Jonathan is Red

Color of GoldenDel is Yellow

Color of RedDel is Red

Color of Winesap is Red

Color of Cortland is Red

Color of McIntosh is Reddish Green

Notice how the 

for

 loops are controlled by a variable of type 



Apple

. Because the 

enumerated values in 

Apple

 start at zero, these values can be used to index 



color

 to obtain 

the color of the apple. Notice that a cast is required when the enumeration value is used to 

index the 



color

 array. As mentioned, there are no implicit conversions defined between 

integers and enumeration types. An explicit cast is required.


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   425   426   427   428   429   430   431   432   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish