Queue.Clone 方法用法 C#

Queue.Clone method usage C#

我找到了以下解决方案Clone function in the documentation on MSDN for the Queue class。 但是在我的代码中,出现以下错误:

private Queue<int> myQueue = new Queue<int>();
var clone = myQueue.Clone();

'System.Collections.Generic.Queue' does not contain a definition for 'Clone' and no extension method 'Clone' accepting a first argument of type 'System.Collections.Generic.Queue' could be found (are you missing a using directive or an assembly reference?)

如何使用这个功能?

Clone 可用于旧的非通用 Queue class.

使用通用队列,您可以执行以下操作:

var copy = new Queue<T>(oldQueue)

您混淆了两种不同的类型: System.Collections.Queue and System.Collections.Generic.Queue<T>

第二个(您正在使用的)没有 Clone 方法。