1 / 72

Uvod v C#

Uvod v C#. Drugi del. Dedovanje. Sintaksa. Prirejanje in preverjanje tipov. Kaste preverjenih tipov. Prekrivanje metod. Dinamično povezovanje (poenostavljeno). Skrivanje. Dinamično povezovanje (s skrivanjem). Fragile base class problem. Konstruktorji in dedovanje.

magdaleno
Download Presentation

Uvod v C#

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. Uvod v C# Drugi del

  2. Dedovanje

  3. Sintaksa

  4. Prirejanje in preverjanje tipov

  5. Kaste preverjenih tipov

  6. Prekrivanje metod

  7. Dinamično povezovanje (poenostavljeno)

  8. Skrivanje

  9. Dinamično povezovanje (s skrivanjem)

  10. Fragile base class problem

  11. Konstruktorji in dedovanje

  12. Vidnost protected in internal

  13. Abstraktni razredi

  14. Abstraktne lastnosti in indekserji

  15. Zapečateni razredi

  16. Vmesniki (interfaces)

  17. Sintaksa

  18. Implementacija vmesnikov

  19. Delo z vmesniki

  20. Primer

  21. Delegati in dogodki

  22. Delegati Delegates are reference types which allow indirect calls to methods. A delegate instance holds references to some number of methods, and by invoking the delegate one causes all of these methods to be called. The usefulness of delegates lies in the fact that the functions which invoke them are blind to the underlying methods they thereby cause to run (see, for instance, the discussion of events, below).

  23. Delegati From this brief description, it can be seen that delegates are functionally rather similar to C++'s 'function pointers'. However, it is important to bear in mind two main differences. Firstly, delegates are reference types rather than value types. Secondly, some single delegates can reference multiple methods

  24. Delegate Declaration and Instantiation Each delegate is limited to referencing methods of a particular kind only. The type is indicated by the delegate declaration - the input parameters and return type given in the delegate declaration must be shared by the methods its delegate instances reference. To illustrate this: a delegate specified as below can be used to refer only to methods which have a single String input and no return value: public delegate void Print (String s);

  25. Suppose, for instance, that a class contains the following method: public void realMethod (String myString){    // method code } Another method in this class could then instantiate the 'Print' delegate in the following way, so that it holds a reference to 'realMethod': Print delegateVariable = new Print(realMethod);

  26. Jezikovna podpora dogodkom Ključna beseda event nam omogoča določiti delegata, ki bo ustrezal poklicanim metodam ob nastopu nekega dogodka.public event AlarmEventHandler Alarm; Dogodek sprožimo s klicem dogodkaAlarm(); Odjemalci se prijavijo na dogodek z operatorjem += eventSource.Alarm += new AlarmEventHandler(eventListener.AlarmRang); Razredi - dogodki

  27. Deklaracija delegata, prireditev metode delegatu

  28. Prirejanje različnih metod

  29. Creating a delegate value

  30. Multicast delegati

  31. Events = Special Delegate Variables

  32. Izjeme (exceptions)

  33. Stavek try

  34. System.Exception

  35. Throwing an Exception

  36. Hierarhija izjem

  37. Searching for a catch Clause

  38. No Throws Clause in Method Signature

  39. Namespaces and Assemblies

  40. C# Namespaces vs. Java Packages

  41. Namespaces vs. Packages (continued)

  42. Assemblies

  43. Kako se tvorijo assemblies

  44. Opcije prevajalnika

  45. Opcije prevajalnika

  46. Primeri prevajanj

  47. Atributi

  48. Atributi so deklarativni elementi jezika pridevniki so na primer tudi deklarativni elementi omogočajo dekoracijo elementov kode z dodatno informacijo assembly, modul, tip, član tipa, return value, parameter Atributi posplošujejo koncept deklarativnega elementa atributi niso omejeni na vnaprej določeno množico lahko se zmišljujemo svoje nove atribute atributi in njihove vrednosti so dosegljivi v času prevajanja in v času izvajanja Atributi [Obsolete("This class is obsolete")] class A { public void F() {} }

  49. Atributi

  50. Atribut s parametri

More Related