Cast object to IEnumerable<object>?

后端 未结 2 1816
余生分开走
余生分开走 2021-02-20 08:33

How can I cast an object to IEnumerable?

I know that the object implements IEnumerable but I don\'t kn
2条回答
  •  情歌与酒
    2021-02-20 09:17

    I ran into the same issue with covariance not supporting value types, I had an object with and actual type of List and needed an IEnumerable. A way to generate an IEnumerable when just IEnumerable isn't good enough is to use the linq Cast method

    ((IEnumerable)lhsValue).Cast()
    
        

    提交回复
    热议问题