I was trying to make a function that returns a boolean: true if all items are the same, false if not. I tought to use a foreach loop to iterate the stack and somehow check if all items are equal or not, but I'm not sure this is the best way.
What i tried is:
bool AllSame(Stack<int> myStack)
{
int check = myStack.Peek();
foreach(int i in myStack)
if(i != check)
return false;
return true;
}
The example above was made with integer values to make things simple, but of course these could be any generic values