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


// Are the references pointing to the same object in memory?



Download 21,46 Mb.
Pdf ko'rish
bet437/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   433   434   435   436   437   438   439   440   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Are the references pointing to the same object in memory?

if (o.Equals(p1) && p2.Equals(o))

{

Console.WriteLine("Same instance!");



}

Console.ReadLine();

}

}

Figure 6-13 shows the output.



Figure 6-13.

Invoking the inherited members of System.Object

First, notice how the default implementation of ToString() returns the fully qualified name of

the current type (ObjectOverrides.Person). As you will see later during our examination of building

custom namespaces (Chapter 15), every C# project defines a “root namespace,” which has the same

name of the project itself. Here, we created a project named ObjectOverrides; thus the Person type

(as well as the Program class) have both been placed within the ObjectOverrides namespace.

The default behavior of Equals() is to test whether two variables are pointing to the same

object in memory. Here, you create a new Person variable named p1. At this point, a new Person

object is placed on the managed heap. p2 is also of type Person. However, you are not creating a new

instance, but rather assigning this variable to reference p1. Therefore, p1 and p2 are both pointing to

the same object in memory, as is the variable o (of type object, which was thrown in for good meas-

ure). Given that p1, p2, and o all point to the same memory location, the equality test succeeds.

Although the canned behavior of System.Object can fit the bill in a number of cases, it is quite

common for your custom types to override some of these inherited methods. To illustrate, update

the Person class to support some state data representing an individual’s first name, last name, and

age, each of which can be set by a custom constructor:

C H A P T E R   6  


Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   433   434   435   436   437   438   439   440   ...   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