Home

C# Convert List<string> To List<int>

Blog Date 17 May 2021

The Code

   List<int> MyIntegerList = MyStringList.ConvertAll(int.Parse);

The Explanation

Lists are handy and in *some* ways easier to work with than arrays. But we've ended up with a list of the type string and we want to add up the contents of the currently string (ie text) numbers in the list. To convert the string number into a list of type integers we use the code above. 

FYI to get a SUM (ie add up all the numbers in our new integer type list) of the integers in the list we use

  int SumOfnumbersInList = MyIntegerList.Sum();


Contact ren@techsolus.co.uk for you coding requirements

Reader's Comments

Post Your Comment Posts/Links Rules

Name

Comment

Add a RELEVANT link (not required)

Upload an image (not required)

No uploaded image
Real person number
Please enter the above number below




Home
Admin Ren's Biking Blog