Why can't I assign List to IEnumerable<object> in .NET 4.0

后端 未结 4 1468
慢半拍i
慢半拍i 2020-12-11 02:44

I try to do this:

IEnumerable ids = new List() { \"0001\", \"0002\", \"0003\" };


it works great!

But wh

4条回答
  •  执念已碎
    2020-12-11 03:09

    Another solution would be to use the extension method Enumerable.Cast as such:

    Dim a as IEnumerable(Of Integer) = GetA()
    
    MethodThatTakesIEnumerableOfObject(a.Cast(Of Object))
    

提交回复
热议问题