I am looking for a one liner that transforms List<T> into object[]. It’s one liner, so I am not interested in solutions such as foreach, or for…
Any takers?
Hint: No, both List<T>.ToArray() and List<T>.ToArray<object>() don’t work.
Edit: Why List<T>.ToArray<object>() doesn’t work? Because it can’t compile.
That will only iterate once, by the way, in case you were wondering about the performance. O(n). 🙂
Why? Well, because
Cast<object>will use deferred execution and won’t actually do anything until the list is iterated byToArray().