I was wondering if it was possible to create 2 constructors inside the same class. I looked up some information and found out that there is a keyword "THIS" that i can use, BUT i wanted to know if it was possible to create 2 constructors in the same class WITHOUT using "THIS".
like for example would i be able to create :
class myClass
{
public constructor_1()
{
//code
}
public constructor_2()
{
//some more code
}
}
class Main()
{
//code
}
Loading
VulpesPosted Oct 7, 2013, 3:13 AM
Incidentally, the 'this' keyword is used when you want to 'chain' constructors together i.e. call one from another. For example:
class MeaningOfLife
{
public MeaningOfLife() : this (42)
{
// default constructor, passes 42 to other one which does the work
}
public MeaningOfLife(int i)
{
// code
}
}
Puneet GuptaPosted Oct 7, 2013, 12:18 AM
http://www.codeproject.com/Articles/7011/An-Intro-to-Constructors-in-C
Thanks,
Puneet Gupta
Veena SardaPosted Oct 7, 2013, 12:04 AM