【转】c#怎样将object[]转换为string[]?

object[] objs = new object[] { "1", "2", "3" };
string[] strs = new string[objs.Length];
objs.CopyTo(strs, 0);

当然必须确保你的object每个对象都是字符串。
如果object数组中有多种对象类型如下:
object[] objs = new object[] { "1", 1, 2.3 }; 那另当别论了。
for(int i=0;i<objs.Length;i++)
{
strs[i] = objs[i].ToString();
}

posted @ 2019-03-08 14:49  纵一苇之所如-  阅读(8898)  评论(0编辑  收藏  举报