Queue.Clone method usage C#

北城以北 提交于 2021-01-27 07:49:15

问题


I have found the following solutions Clone function in the documentation on MSDN for the Queue class. But in my code, i get the following error:

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

How can I use this function?


回答1:


Clone is available for old, non-generic Queue class.

With generic Queue you can do:

var copy = new Queue<T>(oldQueue)



回答2:


You are confusing two different types: System.Collections.Queue and System.Collections.Generic.Queue<T>

The second one (which you are using) doesn't have a Clone method.



来源:https://stackoverflow.com/questions/35438479/queue-clone-method-usage-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!