المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Basic Question On Constructor Stuff



C# Programming
06-03-2011, 02:22 PM
Hi,
is it possible use as argument of reused constructor something calculated in the constructor itself?
something like
Test(double b_):this(b_,c) but where c comes from constructor itself. A simplified example:

lass Test { double area; public Test(double b_) { // here do some operation with b, to obtain c. Now I would like to use // the constructor public Test(b_ , c) // but the syntax Test(double b_):this(b_,c) is not possible since c is initialized // in the constructor double c = b_ * Math.Sqrt(44); //of course I can do: area = b * c; but I want not to rewrite some part of code in //different constructor } public Test(double b_ , double l) { area = b * l; } }
Thanks for your time
TheGermoz