title: Format any object array to string
body: <p>If object is array I want to return string representation of it as follows:</p>
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.Linq;
  using Xunit;
  using Xunit.Abstractions;
  
  namespace Tests.UnitTests
  {
      enum TestEnum {
          A,
          B
      }
  
      public class MyClass {
  
          private readonly ITestOutputHelper _testOutputHelper;
  
          public static string ObjectToString(object? obj) {
              if (obj?.GetType().IsArray == true)
              {
                  return string.Join(&quot;,&quot;, obj); // &lt;-- does not work, returns &quot;Tests.UnitTests.TestEnum[]&quot;
                  return string.Join(&quot;,&quot;, ((object[]) obj).AsEnumerable()); // &lt;-- does not work, throws &quot;Unable to cast object of type 'Tests.UnitTests.TestEnum[]' to type 'System.Object[]&quot;
                  return string.Join(&quot;,&quot;, ((Enum[]) obj).AsEnumerable()); // &lt;-- does not work, throws &quot;Unable to cast object of type 'Tests.UnitTests.TestEnum[]' to type 'System.Enum[]'&quot;
              }
              return obj?.ToString() ?? &quot;&lt;unknown&gt;&quot;;
          }
  
          public MyClass(ITestOutputHelper testOutputHelper)
          {
              _testOutputHelper = testOutputHelper;
          }
  
          [Fact]
          public void Test() {
              var val = new TestEnum[] { TestEnum.A, TestEnum.B };
              var result = ObjectToString(val);
              _testOutputHelper.WriteLine($&quot;RESULT: {result}&quot;);
          }
      }
  }
  
  </code></pre>
  <p>Generally I need to check if obj is array, cast it to &quot;any&quot; array and map it's values to strings. How can I do it? In example I used enum but I want to make it work for array of any type of value, just want to invoke ToString() on each array elements and join result.</p>