KrisTrip KrisTrip - 3 years ago 201
C# Question

Convert System.Array to string[]

I have a System.Array that I need to convert to string[]. Is there a better way to do this than just looping through the array, calling ToString on each element, and saving to a string[]? The problem is I don't necessarily know the type of the elements until runtime.

Answer Source

How about using LINQ?

string[] foo = someObjectArray.OfType<object>().Select(o => o.ToString()).ToArray();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download