aewarnick Posted November 25, 2003 Posted November 25, 2003 class Inherit : c1 { Inherit(){} // calls c1() constructor but not c1(string argument) //which messes things up. //How would I call the constructor with an argument in the base class? } class c1 : UserControl { public c1(){} public c1(string argument) { // argument is used here and is important! } } Quote C#
*Experts* Bucky Posted November 25, 2003 *Experts* Posted November 25, 2003 Instead of doing the initialization inside the constructor of the base class, create a protected or public method in the base class that does the initialization, and then you can call it in both the regular constructor and the inheritor's constructor. class Inherit : c1 { Inherit() { base.InitClass("whatever"); } } class c1 : UserControl { public c1(){} public c1(string argument) { InitClass(argument); } protected void InitClass(string argument) { // Initialize the class with the argument in this sub } } Does this solve your problem? Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
aewarnick Posted November 25, 2003 Author Posted November 25, 2003 Yes, that will solve my problem. Thanks. Quote C#
_SBradley_ Posted December 4, 2003 Posted December 4, 2003 The "correct" way to do what you're after is this: [CS] class Inherit : c1 { Inherit() : base("whatever") { } } class c1 : UserControl { public c1() { } public c1(string argument) { // Initialize the class with the argument in this sub } } [/CS] Quote
aewarnick Posted December 4, 2003 Author Posted December 4, 2003 Thanks. Never saw that before. I'll try it out. Quote C#
_SBradley_ Posted December 8, 2003 Posted December 8, 2003 It's pretty much the same thing as [CS] class Inherit extends c1 { Inherit() { super("whatever"); } } [/CS] in Java. Only nicer. ;) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.