Possible Duplicate:
Parse string to int array
I have string which comes from a numeric textbox like this: 2670053157. how should I split each character of string and insert them into List<int> elements?
Possible Duplicate:
Parse string to int array
I have string which comes from a numeric textbox like this: 2670053157. how should I split each character of string and insert them into List<int> elements?
List<int> numericlist = "2670053157".Select(c => c - '0').ToList();
c - '0'Start out with a helper method:
public static IEnumerable<short> getDigits(long input)
{
while (input > 0)
{
yield return (short)(input % 10);
input /= 10;
}
}
Then if you want the values in a list, just call ToList:
List<short> list = getDigits(2670053157).ToList();
If you want the higher order bits first you'll need to Reverse the sequence:
List<short> list = getDigits(2670053157).Reverse().ToList();