0
Answer

Dynamically accessing methods of a derived class using base class object

Administrator

Administrator

21y
1.2k
1
Hi, I need to access derived class methods/properties using base class object. Implementation goes like this, public interface IBaseComponent { object Properties { get; } } public class BaseComponent : IBaseComponent { public object Properties { get { // Some code to return derived // class Properties } } } public class DerivedComponent : BaseComponent { string Name { get { return "Success"; } } } static void main() { BaseComponent baseobj = new DerivedComponent(); string a = (string)baseobj.Properties.Name; // a should contain string "Success" } ************************************* Any help in this regard will be appreciated. Thanks, Usman