How to call constructor of the current class and parent class at the same time?
Posted
by Siegfried
on Stack Overflow
See other posts from Stack Overflow
or by Siegfried
Published on 2010-05-04T02:14:10Z
Indexed on
2010/05/04
2:18 UTC
Read the original article
Hit count: 244
c#
public class A{
public A(int a, int b) {...}
}
public class B : A{
List a;
List b;
public B(){...} //constructor1
public B(int a, int b) : base(a,b){...} //constructor2
}
My question is I need to initialize both list a and b in class B. If I put them in the constructor1, how can I call constructor1 in constructor2? I don't want to rewrite the initialization statements in constructor2 again. Thanks!
© Stack Overflow or respective owner