I'm having trouble iterating over all possible combinations of enums. I'm not too familiar with them as I've just started C# and am coming in from low level languages like C and assembler.
public enum enumA { A1, A2, A3 }
public enum enumB { B1, B2, B3 }
public class foo
{
private enumA enumAfoo;
private enumB enumBfoo;
public foo()
{
}
public foo(enumA A, enumB B)
{
enumAfoo = A;
enumBfoo = B;
}
}
public class fooTwo
{
private List<foo> allCombinations = new List<foo>();
public fooTwo()
{
}
public List<foo> GetList()
{
return allCombinations;
}
public fooTwo(bool check)
{
if (check)
{
foreach (enumA i in Enum.GetValues(typeof(enumA)))
{
foreach (enumB j in Enum.GetValues(typeof(enumB)))
{
allCombinations.Add(new foo(i, j));
}
}
}
}
}
When I run this code in a simple check output, I don't get what I'm after. Sample Main below. The output I get is just "TestingGround.foo" repeated 6 times, testing ground being my overall namespace. I Don't know if there's a problem with my logic of instantiating the list, or with how I'm converting it to string and outputting but I'd very much like some help in what's the correct procedure for doing this.
class Program
{
static void Main(string[] args)
{
fooTwo A = new fooTwo(true);
List<foo> list = A.GetList();
foreach (foo j in list)
{
Console.WriteLine(j.ToString());
}
Console.ReadKey();
}
}