0

C# Stack error

I'm trying to replicate this example from the C# course Generics: Queue<int> q = new Queue<int>(); q.Enqueue(5); q.Enqueue(10); q.Enqueue(15); Console.Write("Queue: "); foreach (int i in q) Console.Write(i + " "); // 5 10 15 And I have the following error: -foreach statement cannot operate on variables of type 'program.Stack<int>' because 'Program.Stack<int>' does not contain a public instance definition for 'GetEnumerator'-

8th Oct 2019, 12:16 AM
Jorge A. Baños Aguilar
2 Answers
0
U need PUBLIC variables. Define them as public, perhaps it'll get over your problem, i hope.
9th Oct 2019, 6:07 AM
WotanStorm
WotanStorm - avatar
0
Do you have? using System.Collections.Generic;
19th Oct 2019, 10:29 PM
Rustem Sharipov
Rustem Sharipov - avatar