我克隆一摞......不知道,如果它是一个.NET错误或预期的行为时,遇到了这个问题。意见?
昏暗myStack作为新的堆栈(整数)({2,1,3})
回复于(的string.join(,,myStack.Clone)及&所述峰; br>中&安培;的string.join(,,myStack.Clone.Clone))
输出:
2,1,3
3,1,2< - 我的预期2,1,3
解决方案
这是不是一个净的Bug。该的栈(T)
类型并不拥有一种克隆
方法或属性。这表现在以下code不上标准VB.Net控制台项目编译
昏暗堆栈作为新的堆栈(整数)({2,1,3})
Console.WriteLine(的string.join(,,stack.Clone))
在克隆
方法被绑定到必须在项目中的某处定义的扩展方法。该缺陷或设计行为躺在那里。
I came across this problem when cloning a stack... not sure if it's a .NET bug or expected behaviour. Opinions?
Dim myStack As New Stack(Of Integer)({2,1,3})
Response.Write(String.Join(",",myStack.Clone) & "<br>" & String.Join(",",myStack.Clone.Clone))
output:
2,1,3
3,1,2 <- I expected 2,1,3
解决方案
This is not a .Net Bug. The Stack(Of T)
type doesn't posses a Clone
method or property. This is demonstrated by the following code which doesn't compile on a standard VB.Net console project
Dim stack As New Stack(Of Integer)({2, 1, 3})
Console.WriteLine(String.Join(",", stack.Clone))
The Clone
method being bound to must be an extension method defined somewhere in your project. The bug or by design behavior lies there.