Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Invoking constructor in parent class
Message
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00855612
Message ID:
00855639
Vues:
15
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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform