This print for content only-size & color not accurate 7" X 9-1/4" / casebound / malloy


// The "default" keyword is overloaded in C#



Download 21,46 Mb.
Pdf ko'rish
bet657/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   653   654   655   656   657   658   659   660   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// The "default" keyword is overloaded in C#.

// When used with generics, it represents the default

// value of a type parameter.

public void ResetPoint()

{

xPos = default(T);



yPos = default(T);

}

With the introduction of generics, the C# default keyword has been given a dual identity. In



addition to its use within a switch construct, it can be used to set a type parameter to its default

value. This is clearly helpful given that a generic type does not know the actual placeholders up

front and therefore cannot safely assume what the default value will be. The defaults for a type

parameter are as follows:

• Numeric values have a default value of 0.

• Reference types have a default value of null.

• Fields of a structure are set to 0 (for value types) or null (for reference types).

For Point, you could simply set xPos and yPos to 0 directly, given that it is safe to assume the

caller will supply only numerical data. However, by using the default(T) syntax, you increase the

overall flexibility of the generic type. In any case, you can now exercise the methods of Point as

follows:

static void Main(string[] args)

{

Console.WriteLine("***** Fun with Generic Structures *****\n");




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   653   654   655   656   657   658   659   660   ...   1830




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