[RESOLVED] [2.0] How to do
Hi all :wave:
See the class I know that my constructor are wrong but how to use the same constructor for setting different value.
I do not want to use the class property!
C# Code:
class Test
{
private string _CatID;
private string _CatName;
private string _SubCatName;
private string _SubCatMotherName;
public Test(string CatID, string CatName)
{
_CatID = CatID;
_CatName = CatName;
}
public Test(string CatID, string SubCatName)
{
_CatID = CatID;
_SubCatName = SubCatName;
}
public Test(string CatID, string SubCatMotherName)
{
_CatID = CatID;
_SubCatMotherName = SubCatMotherName;
}
}
How to set value through constructor without using the property I have some more variable , above was just little example
Re: [RESOLVED] [2.0] How to do
Maybe use in combination with an enumeration.
Like ...
Code:
public Test(String catID, String name, CatNameKind nameKind)
{
_catID = catID;
switch (nameKind){
case CatNameKind.Normal:
_catName = name;
break;
case CatNameKind.Sub:
_subCatName = name;
break;
case CatNameKind.Mother:
_motherCatName = name;
break;
}
}
In combination with an enumeration like this ...
Code:
public enum CatNameKind{
Normal,
Sub,
Mother
}
Creation gets easy like:
Code:
Test t = new Test("007XV", "KlaartjeTheCat", CatNameKind.Normal);
I hope it's a useful idea :)