C# object to array

前端 未结 5 1535
失恋的感觉
失恋的感觉 2020-12-15 04:40

Using reflection I have an object which I need to cast into an iterable list of items (type unknown, will be object). Using the Watch window I can see my object is an array

5条回答
  •  自闭症患者
    2020-12-15 04:56

    Try this:

        var myList = anArray as IEnumerable;
        if (mylist != null)
        { 
            foreach (var element in myList)
            {
                // etc
            }
        }
    

    You might also need to specify the generic type of the IEnumerable, depending on your situation.

提交回复
热议问题