views:

454

answers:

3

I have two classes declared like this:

class Object1
{
    protected ulong guid;
    protected uint type;

    public Object1(ulong Guid, uint Type)
    {
        this.guid = Guid;
        this.type = Type
    }
    // other details omitted
}

class Object2 : Object1
{
    // details omitted
}

In the client code, I want to be able to create an instance of each object like this:

Object1 MyObject1 = new Object1(123456789, 555);
Object2 MyObject2 = new Object2(987654321, 111);

How can I get Object2 to use Object1's constructor like that? Thankyou.

+8  A: 
class Object2 : Object1
{
   Object2(ulong l, uint i ) : base (l, i)
   {
   }
}
Frederik Gheysels
+1  A: 

You have to provide a constructor with the same signature for Object2 and then call the base class's constructor:

class Object2 : Object1
{
    public Object2(ulong Guid, uint Type) : base(Guid, Type) {}
}
Garry Shutler
+1  A: 

Give Object2 a constructor like this:-

public Object2(ulong Guid, uint Type): base(Guid, Type)
AdamRalph
blast... you have type faster than light speed to get an answer in first on this site! ;-)
AdamRalph
No, you just have to stop the time while you're typing your answer. Easy.
OregonGhost