How to convert object to object[]

前端 未结 4 1777
孤城傲影
孤城傲影 2021-01-17 10:52

I have an object whose value may be one of several array types like int[] or string[], and I want to convert it to a string[]

4条回答
  •  情书的邮戳
    2021-01-17 11:39

    void Do(object value)
    {
        if (value.GetType().IsArray)
        {
           string[] strings = ((object[]) value).Select(obj => Convert.ToString(obj)).ToArray();
        }
    }
    

提交回复
热议问题