array.convertall ] method or linq
select and
toarray functions.
method allows you to use each element that can be used to apply to the array and return the result as a new array. To convert the string array to an integer array, you can use the following syntax:
] int [] myints = array.convertall (arr, s => int.parse (s);
int[] myInts = Array.ConvertAll(arr, s => int.Parse(s));
as a parameter. This lambda expression receives a string to analyze it into an integer and return the conversion integer. The generated integer array is stored in Myints
] variables.
linq solution
or you can use Linq's select
torray
function will be converted to array that will be generated by that will be generated. The grammar of this LINQ solution is as follows:
] int [] myints = Arr.Select (int.parse) .toarray ();
In this case, the
select method uses Lambda expression
int.pars to analyze each element of
Essence Then, the
collection of function will be converted into an integer array that will be generated.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3