Administrator

Administrator

  • Tech Writer
  • 2.2k
  • 1.5m

Dynamically accessing methods of a derived class using base class object

Mar 31 2003 3:56 AM
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