C# 0 The Complete Reference


PART I C h a p t e r   9



Download 4,07 Mb.
Pdf ko'rish
bet294/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   290   291   292   293   294   295   296   297   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART I

C h a p t e r   9 :  

O p e r a t o r   O v e r l o a d i n g  

215


PART IPART I

    result.x = op1.x - op2.x; // these are integer subtractions

    result.y = op1.y - op2.y;

    result.z = op1.z - op2.z;

    return result;

  }


  // Show X, Y, Z coordinates.

  public void Show()

  {

    Console.WriteLine(x + ", " + y + ", " + z);



  }

}

class ThreeDDemo {



  static void Main() {

    ThreeD a = new ThreeD(1, 2, 3);

    ThreeD b = new ThreeD(10, 10, 10);

    ThreeD c;

    Console.Write("Here is a: ");

    a.Show();

    Console.WriteLine();

    Console.Write("Here is b: ");

    b.Show();

    Console.WriteLine();

    c = a + b; // add a and b together

    Console.Write("Result of a + b: ");

    c.Show();

    Console.WriteLine();

    c = a + b + c; // add a, b, and c together

    Console.Write("Result of a + b + c: ");

    c.Show();

    Console.WriteLine();

    c = c - a; // subtract a

    Console.Write("Result of c - a: ");

    c.Show();

    Console.WriteLine();

    c = c - b; // subtract b

    Console.Write("Result of c - b: ");

    c.Show();

    Console.WriteLine();

  }

}

This program produces the following output:



Here is a: 1, 2, 3

Here is b: 10, 10, 10

www.freepdf-books.com



216

 

P a r t   I :  



T h e   C #   L a n g u a g e

Result of a + b: 11, 12, 13

Result of a + b + c: 22, 24, 26

Result of c - a: 21, 22, 23

Result of c - b: 11, 12, 13

Let’s examine the preceding program carefully, beginning with the overloaded operator 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   290   291   292   293   294   295   296   297   ...   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