Search code examples
c#.netarrayssystem.array

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.


Solution

  • How about using LINQ?

    string[] foo = someObjectArray.OfType<object>().Select(o => o.ToString()).ToArray();