Created
August 18, 2019 11:21
-
-
Save alaawahbah/88385bec3570a9e7ba2e19eba3c9d263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
553 | |
Given an array you can use the Array.ConvertAll method: | |
int[] myInts = Array.ConvertAll(arr, s => int.Parse(s)); | |
Thanks to Marc Gravell for pointing out that the lambda can be omitted, yielding a shorter version shown below: | |
int[] myInts = Array.ConvertAll(arr, int.Parse); | |
A LINQ solution is similar, except you would need the extra ToArray call to get an array: | |
int[] myInts = arr.Select(int.Parse).ToArray(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment