Presentation is loading. Please wait.

Presentation is loading. Please wait.

Uvod v C# Drugi del. Dedovanje Sintaksa Prirejanje in preverjanje tipov.

Similar presentations


Presentation on theme: "Uvod v C# Drugi del. Dedovanje Sintaksa Prirejanje in preverjanje tipov."— 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 1.1. public void realMethod (String myString)public void realMethod (String myString) 2.2. { 3.3. // method code // method code 4.4. } 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 Razredi - dogodki 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 dogodka Alarm(); Odjemalci se prijavijo na dogodek z operatorjem += eventSource.Alarm += new AlarmEventHandler(eventListener.AlarmRang);

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

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 [Obsolete("This class is obsolete")] class A { public void F() {} }

49 Atributi

50 Atribut s parametri

51 Atributi Nekateri vnaprej definirani atributi Ime atributaOpis Browsable Vključenost lastnosti v okno lastnosti Serializable Določa naj bo razred ali struktura serializabilna Obsolete Določa, da je nek element kode zastarel Conditional Določa vključenost metode v odvisnosti od predproc. simbola

52 Atributi Zgled uporabe atributa Conditional #define Debug public class Debug { [Conditional("Debug")] public static void Assert(bool cond, String s) { if (!cond) { throw new AssertionException(s); } void DoSomething() {... // If Debug is not defined, the next line is // not even called Assert((x == y), “X should equal Y”);... }

53 Še en primer: atribut Conditional

54 Tvoji lastni atributi

55 Niti (threads)

56 Sodelujoče niti (participating threads)

57 Primer

58 Stanja niti

59 Primer za Join

60 Medsebojno izobčenje (sinhronizacija)

61 Razred Monitor

62 Wait in Pulse

63 Primer: sinhroniziran medpomnilnik

64 Komentarji XML

65 Posebni komentarji (podobno javadoc)

66 Primer komentirane kode

67 Tvorjena XML datoteka

68 XML oznake (XML tags)

69 Povzetek C#

70 Odprtokodni c# MCS: The Ximian C# compiler The Mono C# compiler is considered feature C# 1.0 complete at this point and mature. MCS is able to compile itself and many more C# programs (there is a test suite included that you can use). It is routinely used to compile Mono, roughly 1.7 million lines of C# code. The compiler is also fairly fast. On a IBM ThinkPad t40 it compiles 18,000 lines of C# code per second. Work on C# 2.0 has started: some pieces of it are available on the standard compiler with the -2 switch (iterators, method conversions) and some others are available on the `gmcs' branch on CVS (generics) Obtaining MCS The Mono C# compiler is part of the `mcs' module in the Mono CVS you can get it from our Anonymous CVS server, or you can get nightly download page.Anonymous CVSdownload page

71 Mono razhroščevalnik

72 Eclipse in mono


Download ppt "Uvod v C# Drugi del. Dedovanje Sintaksa Prirejanje in preverjanje tipov."

Similar presentations


Ads by Google