Reputation: 35
So I have a stack of a few stacks.
This is how I implemented the stack: public Stack<Stack<Baggage>> Trunk;
So trunk is supposed to hold multiple stacks of baggage (one baggage stack has a limited number of bags it can hold)
The question I have is, how would I write out the trunk stack.
Ive tried using the pop() function but on the console it writes out this: System.Collections.Generic.Stack
1[TestDummy.Baggage]` I tried making an override ToString method in the baggage class but it doesn't work.
thank you for your help!
Upvotes: 0
Views: 77
Reputation: 61
From what I understood, you are trying to print Trunk
content to console. You must keep in mind that inside your Trunk
stack there are another stacks, so you should pop a value from that stack too, to get it
Here is a simple example code:
foreach(var baggage in Trunk.Pop())
{
Console.WriteLine(baggage.Name);
}
Trunk.Pop()
will take off stack from Trunk
and foreach
loop will iterate through elements of that stack and perform some action
Upvotes: 2