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 -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -