判断是不是IEnumerable
Array和String[] 都是IEnumerable
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string[] a = new string[1] { "aaa"};
Console.WriteLine(a is IEnumerable);
Array myArr = Array.CreateInstance(typeof(int), 2, 3, 4);
Console.WriteLine(myArr is IEnumerable);
string b = "bbbb";
Console.WriteLine(b is IEnumerable);
}
初始化Array
Array myArr = Array.CreateInstance(typeof(int), 2, 3, 4);
将Array转换成string[]
string[] foo = someObjectArray.OfType<object>().Select(o => o.ToString()).ToArray();