16
public CArm(Vector3 at, string name) : base(name)
{

}

Is there any other way to call base parent constructor within the brackets instead of doing : base(name)?

I'm not sure if this was another language but I recall something like super(); inside of the constructor to call the base class.

Thanks.

Mamta D
  • 6,050
  • 3
  • 24
  • 41
RoR
  • 14,904
  • 22
  • 67
  • 92

2 Answers2

20

No, you cannot call base constructors inside constructor bodies in C#. You're probably thinking of Java's syntax.

You can emulate the desired behavior by calling a method instead. Just make sure to be very careful about calling virtual methods!

Jonas Høgh
  • 9,858
  • 1
  • 23
  • 44
  • 2
    Or VB.NET's syntax, but the call to the base constructor still must be the *first line* in the constructor. – Cody Gray Nov 18 '10 at 07:59
3

no, you can't . super keyword is used in java for calling superclass methods and objects.

Nikki
  • 3,306
  • 13
  • 35
  • 59