Cast received object to a List<object> or IEnumerable<object>

后端 未结 8 1573
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-07 23:52

I\'m trying to perform the following cast

private void MyMethod(object myObject)  
{  
    if(myObject is IEnumerable)  
    {
        List c         


        
      
      
      
8条回答
  •  一整个雨季
    2020-12-08 00:24

    Do you actually need more information than plain IEnumerable gives you? Just cast it to that and use foreach with it. I face exactly the same situation in some bits of Protocol Buffers, and I've found that casting to IEnumerable (or IList to access it like a list) works very well.

提交回复
热议问题