Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Invoking constructor in parent class
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00855612
Message ID:
00855639
Views:
13
Hi, Steve. Give this a try.
using System;

namespace ConsoleApplication1
{
  class Test
  {
    [STAThread]
    static void Main(string[] args)
    {
      DerivedClass test1 = new DerivedClass();
      DerivedClass test2 = new DerivedClass("test2");
    }
  }

  public class BaseClass
  {
    public BaseClass(string Argument)
    {
      Console.WriteLine("BaseClass Constructor with argument - " + Argument);
  }

  public BaseClass()
  {
      Console.WriteLine("BaseClass Constructor (no arguments)");
    }
  }

  public class DerivedClass : BaseClass
  {
    public DerivedClass(string myParm) : base(myParm)
    {
      Console.WriteLine("DerivedClass Constructor - " + myParm);
    }

    public DerivedClass() : base()
    {
      Console.WriteLine("DerivedClass Constructor (no arguments)");
    }
  }
}
Kelly

>When I instantiate the derived class, I want to invoke the base class's constructor, passing the optional argument but can't seem to figger out how this is done.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform