1 / 9

C# interfészek

C# interfészek. Krizsán Zoltán iit 1.0. Definició. Absztrakt függvények gyűjteménye. Egy osztály nyilvános fv.einek a halmaza. Egy osztály használatának módja. Egy viselkedés. Egy osztály vagy struktúra több interfészt is implementálhat. Tartalma. absztrakt fv.ek

raleigh
Download Presentation

C# interfészek

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C# interfészek Krizsán Zoltán iit 1.0

  2. Definició • Absztrakt függvények gyűjteménye. • Egy osztály nyilvános fv.einek a halmaza. • Egy osztály használatának módja. • Egy viselkedés. • Egy osztály vagy struktúra több interfészt is implementálhat.

  3. Tartalma • absztrakt fv.ek • tulajdonság prototypusok • pl: int Kor{get;} • események • indexerek

  4. Implementáció • Osztály, struktúra implementálhatja class osztály : [Ősosztály,]Interfész[,interfész2,…] { } • Visual studio generál üres fv.-eket és megjelöli azokat. • Ha van ősosztály, akkor első helyen kell szerepelnie!

  5. Használat • as, is, cast operátor • Lehet: • fv. paraméter • fv. visszatérési érték • tömb elem

  6. Fontosabb felüldefiniálandó interfészek • IEnumerable • ICloneable • IComparable

  7. IEnumerable publicinterfaceIEnumerator { boolMoveNext (); // Advance the internal position of the cursor. object Current { get;} // Get the current item (read-only property). void Reset (); // Reset the cursor before the first member. }

  8. ICloneable • osztalyobj = newosztaly(); • obj2 = obj; // csak referencia másolás • Ha másik példány kell, akkor clone() publicinterfaceICloneable { objectClone(); }

  9. IComparable • Array.Sort() használahtó ha az elemek implementálják. • CompareTo eredménye • negatív, ha a kapott obj, előrébb van • pozitív, ha a kapott obj, hátrébb van • 0 ha azonos pozició publicinterfaceIComparable { int CompareTo(object o); }

More Related