C# 0 The Complete Reference


PART I C h a p t e r   1 2



Download 4,07 Mb.
Pdf ko'rish
bet416/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   412   413   414   415   416   417   418   419   ...   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  

321


PART IPART I

// Implement ISeries.

class ByTwos : ISeries {

  int val;

  public ByTwos() {

    val = 0;

  }

  // Get or set value using a property.



  public int Next {

    get {

      val += 2;

      return val;

    }

    set {



      val = value;

    }


  }

  // Get a value using an index.

  public int this[int index] {

    get {

      val = 0;

      for(int i=0; i < index; i++)

        val += 2;

      return val;

    }

  }


}

// Demonstrate an interface indexer.

class SeriesDemo4 {

  static void Main() {

    ByTwos ob = new ByTwos();

    // Access series through a property.

    for(int i=0; i < 5; i++)

      Console.WriteLine("Next value is " + ob.Next);

    Console.WriteLine("\nStarting at 21");

    ob.Next = 21;

    for(int i=0; i < 5; i++)

      Console.WriteLine("Next value is " +

                         ob.Next);

    Console.WriteLine("\nResetting to 0");

    ob.Next = 0;

    // Access series through an indexer.

    for(int i=0; i < 5; i++)

      Console.WriteLine("Next value is " + ob[i]);

  }

}

www.freepdf-books.com




322

 

P a r t   I :  



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

The output from this program is shown here:

Next value is 2

Next value is 4

Next value is 6

Next value is 8

Next value is 10

Starting at 21

Next value is 23

Next value is 25

Next value is 27

Next value is 29

Next value is 31

Resetting to 0

Next value is 0

Next value is 2

Next value is 4

Next value is 6

Next value is 8

Interfaces Can Be Inherited

One interface can inherit another. The syntax is the same as for inheriting classes. When a 

class implements an interface that inherits another interface, it must provide implementations 

for all the members defined within the interface inheritance chain. Here is an example:

// One interface can inherit another.

using System;

public interface IA {

  void Meth1();

  void Meth2();

}

// B now includes Meth1() and Meth2() -- it adds Meth3().



public interface IB : IA {

  void Meth3();

}

// This class must implement all of IA and IB.



class MyClass : IB {

  public void Meth1() {

    Console.WriteLine("Implement Meth1().");

  }


  public void Meth2() {

    Console.WriteLine("Implement Meth2().");

  }

  public void Meth3() {



    Console.WriteLine("Implement Meth3().");

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   412   413   414   415   416   417   418   419   ...   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