inheritance - c# - How to get property value from derived class? -


this question has answer here:

i writing console app in c#.

here code:

interface itest {     string str { get; } }  public class baseclass : itest {     public virtual string str     {                 {             return "baseclass";         }     } }  public class derivedclass : baseclass {     public new string str {         {             return "derivedclass";         }     } } class program {     static void main(string[] args)     {         itest itest = new derivedclass();          console.writeline(itest.str);         console.readkey();     } } 

when executing above code, "baseclass" coming output. instead, how "derivedclass" output?

with declaring property new in derived class you're creating new member isn't called when invoked through interface. use override instead.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

python - Error: Unresolved reference 'selenium' What is the reason? -

php - Need to store a large amount of data in session with CI 3 but on storing large data in session it is itself destorying automatically -