-3

for example suppose that I have a string like "231143" and I wanna convert it to an int[] array which I can easily access 2,3,1,1,4,3 as an int. What should I do?

Ali Fata
  • 3
  • 1

1 Answers1

1

Without any error checking you can do:

var value = "231143";
var array = value.Select(c => c - '0').ToArray();

This makes use of a trick whereby you can subtract '0' from the value of a single character holding a number to get its integer value.

Sean
  • 60,939
  • 11
  • 97
  • 136