简体   繁体   中英

Convert string[][] to int[][]

I am trying to simply convert the type of jagged arrays:

I would like to do it using something like:

int[][] jaggedArray = Array.ConvertAll(jaggedArrayString, int.Parse)

or

int[][] jaggedArray = Array.ConvertAll(jaggedArrayString, delegate(string s) { return int.Parse(s); }

With Linq, I can't do it that way either

int[][] jaggedArray = jaggedArrayString.Select(int.Parse).ToArray();

I didn't find any solution, is there any easy way to do it?

If you want to use LINQ, you need to Select the strings in each sub array, so you need nested Select s:

int[][] result = arr.Select(x => 
                     x.Select(int.Parse).ToArray()
                 ).ToArray();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM