0
public void ReadData(object Ob) {
 if(Ob.GetType().IsGenericType && Ob is IList) {
      // what I tested
      IList theList = (IList)Ob;
      Console.WriteLine(theList.ToArray()); // compiler error `IList` has not a method called ToArray
  }
}

how can I convert the object to a array. when the object is a IList

irooo
  • 3
  • 2

1 Answers1

0

Maybe you can do this instead:

public void ReadData(object Ob) {
 if(Ob.GetType().IsGenericType && Ob is IList) {

      IList theList = (IList)Ob;            
      Array array = new object[theList.Count];
      theList.CopyTo(array, 0);
      Array.ForEach(array , Console.WriteLine);
  }
}
Mahsa
  • 362
  • 2
  • 15