我有接受类型的参数IEnumerable(Of IEnumerable(Of MyType))
铸造清单的IEnumerable((的的MyType)列出的)(IEnumerable的(的的MyType)的)
如果我以下的方法:
Dim list1 as new List(Of MyType) From { obj1, obj2 }
Dim list2 as new List(Of MyType) From { obj3, obj4 }
MyMethod({ list1, list2 })
它的工作原理是
。
如果我通过一个List(Of List(Of MyType))
它编译但给人运行时错误,如下:
System.InvalidCastException: Unable to cast object of type
'System.Collections.Generic.List`1[System.Collections.Generic.List`1[MyType]]' to type
'System.Collections.Generic.IEnumerable`1[System.Collections.Generic.IEnumerable`1[MyType]]'
如果我通过一个MyType()()
它给编译时错误,如下:
Value of type '2-dimensional array of MyType' cannot be converted to
'System.Collections.Generic.IEnumerable(Of System.Collections.Generic.IEnumerable(Of MyType))'
我目前使用.net 3.5。
这似乎是我所听见的.NET 4
解决任何想法,以避免这个错误类似于Casting List<MyObject> to IEnumerable<MyInterface>的问题吗?
感谢您的答复。顺便说一句,我真的不明白为什么{list1,list2}被接受。你能解释我这种行为吗? – Teejay
另外,你能解释我'收益率'吗?已经看到它,但不知道如何以及为什么使用它。 – Teejay
我用更多的解释和例子更新了我的答案。 – Jamey