将 System.Array 转换为 string[] [英] Convert System.Array to string[]

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

问题描述

我有一个 System.Array,我需要将它转换为 string[].有没有比循环遍历数组、在每个元素上调用 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 转换为 string[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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