Skip to content

Instantly share code, notes, and snippets.

@alaawahbah
Created August 18, 2019 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alaawahbah/88385bec3570a9e7ba2e19eba3c9d263 to your computer and use it in GitHub Desktop.
Save alaawahbah/88385bec3570a9e7ba2e19eba3c9d263 to your computer and use it in GitHub Desktop.
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