C#
Download
1 / 42

Курс по програмиране на C# - PowerPoint PPT Presentation


  • 138 Views
  • Uploaded on
  • Presentation posted in: General

Курс по програмиране на C#. Занятие № 9 Наследяване. Видимост и капсулиране. Съдържание. Наследяване Наследяване в C# Превръщане на типове нагоре и надолу по йерархията Видимост Капсулиране. Наследяване. Какво е „наследяване“? Основен принцип в ООП

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha

Download Presentation

Курс по програмиране на 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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


C#

9.


  • C#


  • ?

    • -; -

    • -; - , -

    • ( ); C#


    • <- , , ,

    • <- , , , ,

    • <- , , , ,

    • <- ,

    • <- , ,

    • <- , , ,

    • <- ,

    • <-TXT , HTML , XML

    • <- , , ,

    • <- , ,


  • ?

    • -

    • ,


    • ,

    • , ,

    • -


C#

    • ,

    • ..

    • , object

    • ;


C#

// - classAnimal{publicstringSpecies;publicintWeight;publicint Age;publicvoid Vocalize() { }}

// classDog : Animal{publicstringBreed;publicstring Name;publicvoid Vocalize() {Console.WriteLine("Woof!"); }}

class

( )

, object

( )


-

//


C#

    • ,

    • , base.

    • , ,


C#

classAnimal{//...publicstringGetDescription() {returnstring.Format("Species: {0}; Age:{1}",Species,Age); }}

classDog : Animal{//...publicstringGetDescription(){returnstring.Format("{0}; Breed: {1}; Name: {2}",base.GetDescription(),Breed,Name); }}

base

.


-

//


C#

    • , ,

    • , -

    • ,


C#

classAnimal{//...publicAnimal(){}publicAnimal(string species) {Species = species; }}

classDog : Animal{//...publicDog(): base("Canis lupus familiaris"){ }publicDog(string breed) {Species = "Canis lupus familiaris";Breed = breed; }}

-

base


-

//


    • , ,

    • A B, B (, B A)

    • ( )


  • (upcasting)

    • A B

    • A B

    • : B - A

    • ( )

    • : object


// DogDogdog = newDog("German shepherd");

// // AnimalAnimalanimal = dog;

// // ((Animal)dog).Vocalize();


-

//


  • (downcasting)

    • A B

    • B A

    • : A - B

    • B,

    • , ( )


// na Dog// AnimalAnimalanimal = newDog("Poodle");

// // DogDogdog = (Dog)animal;

// // Console.WriteLine(((Dog)animal).Breed);

, ,

,


-

//


    • A B

    • is , A, B

    • is ,

    • as ; , null

    • as


// AnimalAnimalanimal = newAnimal("Felissilvestriscatus");

// // // isif(animal isDog){Console.WriteLine( ((Dog)animal).Breed);}

// // asDogdog = animal asDog;if(dog != null)Console.WriteLine(dog.Breed);

is

,

is

,

as

,

as

,


-

//


  • ?

    • ,

    • ( , , , )

    • ( , )


  • C#

    • /

    • ,


  • C#

    • private ( )

    • protected

    • public

    • internal

    • internal protected , ,


classMailMessage{privatestring _subject;

protectedMailMessage(string subject){ _subject = subject;}

publicstringGetSubject(){return_subject;}

internalvoid Send(){// ...}}

,

,

,

,


-

//


  • C#

    • (, , .)

    • public

    • internal ( )


publicclassMusicAlbum{// ...}

publicenumMusicGenre{// ...}

internalclassAlbumCollection{// ...}

internalstructUserInfo{// ...}

,

,


-

//


  • ?


  • ?

    • ,


    • - ,

    • , ,

    • ( ; ; ; )

    • , ,


-

//


  • , :

    • : ( )

    • Object2D (: ) Object3D (: )

    • / ( upcasting downcasting)


  • :

    • (; ; )

      • (; )

        • (: , , ; . ; )

        • (; ; )

      • ( ; /; )

        • ( ; )

        • ( ; / ; )

          • (; )

          • ( ; : , , )


  • :

    • ,

    • ( ), ,

    • ,

    • , , , ;

    • : ( , , / )

    • :


?


!

    • sasho@david.bg

    • Skype: musasho

    • https://facebook.com/adalemski

    • acad@david.bg

    • http://acad.david.bg/

    • @david_academy

    • https://facebook.com/DavidAcademy


ad
  • Login