Hier ist der Code:Versetzt Stack <> Konstruktor den Stapel, wenn er von einem anderen initialisiert wird?
var s = new Stack<int>();
s.Push(1);
s.Push(2);
s.Push(3);
s.Push(4);
var ns = new Stack<int>(s);
var nss = new Stack<int>(new Stack<int>(s));
und dann lass uns
tbLog.Text += "s stack:";
while(s.Count > 0)
{
tbLog.Text += s.Pop() + ",";
}
tbLog.Text += Environment.NewLine;
tbLog.Text += "ns stack:";
while (ns.Count > 0)
{
tbLog.Text += ns.Pop() + ",";
}
tbLog.Text += Environment.NewLine;
tbLog.Text += "nss stack:";
while (nss.Count > 0)
{
tbLog.Text += nss.Pop() + ",";
}
erzeugt die folgende Ausgabe sehen das Ergebnis:
s stack:4,3,2,1,
ns stack:1,2,3,4,
nss stack:4,3,2,1,
So wird ns
Stapel zurück s
Stapel und nss
Stapel ist das gleiche wie s
Stapel.
Dies ist keine Frage, oder? ;) –
Stellen Sie hier eine Frage? Es scheint, dass Sie nur eine Schlussfolgerung veröffentlichen. Schließen. – Oded
@Kieren, @Oded: Ich behandle das als "Ich sehe etwas komisches, ist das richtig?" Die Frage ist im Titel, der Text ist warum wird das Q gefragt. – Richard