tags:

views:

40

answers:

3

Let's say I have a father and son who should be both non abstract and i wont to go around the father c'tor what I have done is this :

 public class D
{
    public D(int x) { }

    public D()
    {
        Console.WriteLine("D:constructor");
    }

}
public class E:D
{
    public E() : base(1)
    {
        Console.WriteLine("E:constructor");
    }

}

Is there another way more elegant to go around the father constructor ?

EDIT: this is just a sample I do have a reason for the inertness is at a god practice or just cause the c'tor is different i should build another design?

A: 

No , This is the way c# supports base class constructor what i have seen yet.

saurabh
A: 

There is no way to get around the base constructor. Even of you implement the above, you're still going through 'a' constructor, but that's the best you can do.

Pieter
A: 

This is the way base constructor's are handled in c#. The only more elegant solution I could suggest is to do very little in your default constructor within your father class. Possibly only initializing proper attributes, or maybe not doing anything. That way if you don't want it to output "D:constructor" you can still use the default constructor for E, without calling the base constructor that requires an int.

The issue isn't with the way it was designed, it's with the way you are creating your constructors.

jsmith
@jsmith so the best way is to use a virtual meethod and it would be the one who changes ?
yoav.str