c# - What's wrong in this interface use? -


suppose have interface this:

interface myinterface  {     public string aproperty { get; set;}      public void amethod () } 

this interface used inside interface:

interface anotherinterface {     public myinterface member1 { get; set; }      public int yetanotherproperty {get; set;} } 

now suppose have 2 classes, 1 implements each of interfaces.

class myinterfaceimpl : myinterface {     private string aproperty     public string aproperty     {         //... , set inside     }      public void amethod ()     {        //...     } } 

and @ last:

class anotherinterfaceimpl : anotherinterface {     private myinterfaceimpl _member1;     public myintefaceimpl member1     {         //... , set inside     }      ...other implementation } 

why compiler complain anotherinterfaceimpl not implement myinterface?

i understand basic question... need serialize xml anotherinterfaceimpl , cannot if member1 of type myinterface.

your class anotherinterfaceimpl not implementing members of anotherinterface. public property anotherinterfaceimpl.member1 must have type myinterface, not myinterfaceimpl.

note restriction applies public property. private field anotherinterfaceimpl._member1 can still of type myinterfaceimpl, because myinterfaceimpl implements myinterface.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -