转换的System.Array到字符串[] [英] Convert System.Array to string[]

查看:155
本文介绍了转换的System.Array到字符串[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我需要转换为字符串[]一个的System.Array。有没有更好的办法不是通过阵列只是循环,调用toString每个元素,并将其保存到字符串[]要做到这一点?问题是我并不知道的元素,直到运行时类型。

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.

推荐答案

如何使用LINQ?

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

这篇关于转换的System.Array到字符串[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆