1. ホーム
  2. c#

[解決済み] How do I convert an Array to a List<object> in C#?

2023-06-23 11:33:17

Question

How do I convert an Array to a List<object> in C#?

How to solved?

List<object> list = myArray.Cast<Object>().ToList();

If the type of the array elements is a reference type, you can leave out the .Cast<object>() since C#4 added interface co-variance i.e. an IEnumerable<SomeClass> can be treated as an IEnumerable<object> .

List<object> list = myArray.ToList<object>();