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

4x4 Matrix in Python -

python - PyInstaller UAC not working in onefile mode -

wso2is - WSO2 IS 5.0.0 SP1 After restart there is authentication error -