C# Objektno

  • View
    236

  • Download
    2

Embed Size (px)

Text of C# Objektno

  • 7/23/2019 C# Objektno

    1/240

    Programski jezik

    C#

    Osnoveobjektnega

    programiranja

    Gregor Jere, Matija Lokar in Sreo Urani

    V 0.9

    marec 2009

  • 7/23/2019 C# Objektno

    2/240

    C# . NET

    Programiranje 1 VS Informatika

    2

  • 7/23/2019 C# Objektno

    3/240

    C# . NET

    Programiranje 1 VS Informatika

    3

  • 7/23/2019 C# Objektno

    4/240

    C# . NET

    Programiranje 1 VS Informatika

    4

    Predgovor

    Omenjeno gradivo pokriva osnove objektnega programiranja v C# .

    Gradivo vsekakor ni dokonano in predstavlja delovno razliico. V njem so zagotovo napake (upava, da

    immanj), za katere se vnaprej opraviujeva. Da bo laje spremljati spremembe, obstaja razdelek Zgodovina

    sprememb, kamor bova vpisovala spremembe med eno in drugo razliico. Tako bo nekomu, ki si je prenesel

    starejo razliico, laje ugotoviti, kaj je bilo v novi razliici spremenjeno.

    Gregor Jere, Matija Lokar in Sreo Urani

    Kranj, november 2008

  • 7/23/2019 C# Objektno

    5/240

    C# . NET

    Programiranje 1 VS Informatika

    5

    Zgodovina sprememb

    14. 11. 2008: Razliica V0.8 le prenos (e neurejeno) Matijevega, Gregorjevega (str. 1120) in Saovegagradiva. Premisliti je e potrebno kaj in kako.5. 3. 2009: Razliica V0.9 e vedno povsem neurejeno. Dodano nekaj gradiva, ki ga je smiselno vkomponirati.Gradivo dodano na konec in sicer:

    Vsebina prosojnic, ki naj bi bile spredavane letos Zgled za Avto Gradivo, ki pokriva uvod v OOP iz C++. Tam je nekaj smiselnih zgledov, ki pa jih je potrebno prepisati v

    C#.

  • 7/23/2019 C# Objektno

    6/240

    C# . NET

    Programiranje 1 VS Informatika

    6

    KAZALO

    Objektno programiranje ...................................................................................................................................... 9

    Motivacija ....................................................................................................................................................... 9Objektno usmerjeno programiranje kaj je to .............................................................. ................................ 10Objekti........................................................................................................................................................... 11Objekti........................................................................................................................................................... 13Programiranje v C# ....................................................................................................................................... 14Objekti........................................................................................................................................................... 14Klasino/objektno programiranje ............................................................. ..................................................... 14Od kje razredi? .............................................................................................................................................. 15Objekt in ime spremenljivke ......................................................................................................................... 15Ustvarjanje objektov ..................................................................................................................................... 15C# in objekti .................................................................................................................................................. 15Ustvarjanje objektov ..................................................................................................................................... 16Zgled ............................................................................................................................................................. 16Objektno programiranje ................................................................................................................................ 18

    Objekti, razredi, ... ............................................................................................................................................ 19Zdruevanje podatkov ........................................................ ................................................................. .......... 19Uporaba razreda Zajec .................................................................................................................................. 21Dostop do podatkov v objektu ...................................................................................................................... 22e en primer - Ulomek .................................................................................................................................. 25Povzetek ........................................................................................................................................................ 26Konstruktorji ................................................................................................................................................. 26this ................................................................................................................................................................. 27

    Uporaba razreda: ........................................................................................................................................... 28Privzeti konstruktor ....................................................................................................................................... 28Ve konstruktorjev ........................................................................................................................................ 29Preobteene metode ...................................................................................................................................... 29Konstruktorji razreda Zajec navzkrino sklicevanje .................................................................................. 30e malo o this .......................................................... ................................................................. ..................... 30Zgled ............................................................................................................................................................. 31Objektne metode ........................................................................................................................................... 34

    Zgledi .......................................................................................................... ...................................................... 37Datum ........................................................... ................................................................. ................................ 37Fibonaccijevo zaporedje................................................................................................................................ 38

    Vaje ................................................................................................................................................................... 40

    Kochova rta ................................................................................................................................................. 40Razred Toka in Kochova rta ...................................................................................................................... 40Ulomek ......................................................... ................................................................. ................................ 40Razred Majica ............................................................................................................................................... 40Razred Zajec ................................................................................................................................................. 41Razred Kolega ......................................................... ................................................................. ..................... 41Uporaba razreda Kolega ..................................................... ................................................................. .......... 41Uporaba razreda Zajec .................................................................................................................................. 42Datum ........................................................... ................................................................. ................................ 42Zajci z datumom............................................................................................................................................ 42Uporaba razreda Zajec z datumom ........................................................... ..................................................... 42

    Nadgradimo datum ............................................................. ................................................................. .......... 42

    Dostop do stanj objekta .......................................................... ................................................................. .......... 42Dostopi do stanj ............................................................................................................................................ 43Zgledi ............................................................................................................................................................ 48

  • 7/23/2019 C# Objektno

    7/240

    C# . NET

    Programiranje 1 VS Informatika

    7

    Dostop do stanj/lastnosti ...........

Search related