2016-02-16 24 views
3

我找到以下解決方案Clone function in the documentation on MSDN for the Queue class。 但在我的代碼,我得到以下錯誤:Queue.Clone方法用法C#

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?)

如何使用這個功能呢?

回答

4

Clone適用於舊的非通用Queue類。

隨着通用的隊列,你可以這樣做:

var copy = new Queue<T>(oldQueue)