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



Download 21,46 Mb.
Pdf ko'rish
bet499/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   495   496   497   498   499   500   501   502   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

Classes, Objects, and References

To frame the topics examined in this chapter, it is important to further clarify the distinction

between classes, objects, and references. Recall that a class is nothing more than a blueprint that

describes how an instance of this type will look and feel in memory. Classes, of course, are defined

within a code file (which in C# takes a *.cs extension by convention). Consider a simple Car class

defined within a new C# Console Application project named SimpleGC:



// Car.cs

public class Car

{

private int currSp;



private string petName;

public Car(){}

public Car(string name, int speed)

{

petName = name;



currSp = speed;

}

public override string ToString()



{

return string.Format("{0} is going {1} MPH",

petName, currSp);

}

}



245

C H A P T E R   8

8849CH08.qxd  10/22/07  1:27 PM  Page 245



Once a class is defined, you can allocate any number of objects using the C# new keyword.

Understand, however, that the new keyword returns a reference to the object on the heap, not the

actual object itself. This reference variable is stored on the stack for further use in your application.

When you wish to invoke members on the object, apply the C# dot operator to the stored reference:

class Program

{

static void Main(string[] args)



{


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   495   496   497   498   499   500   501   502   ...   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