C#
This presentation is the property of its rightful owner.
Sponsored Links
1 / 42

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


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

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

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

C#

9.


C

  • C#


C

  • ?

    • -; -

    • -; - , -

    • ( ); C#


C

    • <- , , ,

    • <- , , , ,

    • <- , , , ,

    • <- ,

    • <- , ,

    • <- , , ,

    • <- ,

    • <-TXT , HTML , XML

    • <- , , ,

    • <- , ,


C

  • ?

    • -

    • ,


C

    • ,

    • , ,

    • -


C

C#

    • ,

    • ..

    • , object

    • ;


C

C#

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

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

class

( )

, object

( )


C

-

//


C

C#

    • ,

    • , base.

    • , ,


C

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

C#

    • , ,

    • , -

    • ,


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


C

-

//


C

    • , ,

    • A B, B (, B A)

    • ( )


C

  • (upcasting)

    • A B

    • A B

    • : B - A

    • ( )

    • : object


C

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

// // AnimalAnimalanimal = dog;

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


C

-

//


C

  • (downcasting)

    • A B

    • B A

    • : A - B

    • B,

    • , ( )


C

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

// // DogDogdog = (Dog)animal;

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

, ,

,


C

-

//


C

    • A B

    • is , A, B

    • is ,

    • as ; , null

    • as


C

// 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

  • ?

    • ,

    • ( , , , )

    • ( , )


C

  • C#

    • /

    • ,


C

  • C#

    • private ( )

    • protected

    • public

    • internal

    • internal protected , ,


C

classMailMessage{privatestring _subject;

protectedMailMessage(string subject){ _subject = subject;}

publicstringGetSubject(){return_subject;}

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

,

,

,

,


C

-

//


C

  • C#

    • (, , .)

    • public

    • internal ( )


C

publicclassMusicAlbum{// ...}

publicenumMusicGenre{// ...}

internalclassAlbumCollection{// ...}

internalstructUserInfo{// ...}

,

,


C

-

//


C

  • ?


C

  • ?

    • ,


C

    • - ,

    • , ,

    • ( ; ; ; )

    • , ,


C

-

//


C

  • , :

    • : ( )

    • Object2D (: ) Object3D (: )

    • / ( upcasting downcasting)


C

  • :

    • (; ; )

      • (; )

        • (: , , ; . ; )

        • (; ; )

      • ( ; /; )

        • ( ; )

        • ( ; / ; )

          • (; )

          • ( ; : , , )


C

  • :

    • ,

    • ( ), ,

    • ,

    • , , , ;

    • : ( , , / )

    • :


C

?


C

!

    • [email protected]

    • Skype: musasho

    • https://facebook.com/adalemski

    • [email protected]

    • http://acad.david.bg/

    • @david_academy

    • https://facebook.com/DavidAcademy


  • Login