Hello. Brilliant forum by the way. Why doesn't this work please?
- public void InitializePack()
- {
- Card [] pack=new Card[52];
- for (int i = 0; i < 4; i++) {
- for (int j = 1; j < 14; j++) {
- pack[(i*13)+j-1] = new Card((Suits)i, (Values)j);
- }
- }
- foreach (Card c in pack)
- Console.WriteLine(c.Name);
- }
c is null at first iteration. I have only seen examples of foreach iterating through arrays whose elements are defined at declaration using {}. Is this the issue?
I've not included the rest of the code as I thought you'd see this one straight away.
Thanks very much!