-4

I have a long number that I want to convert to a list of integers corresponding to decimal digits.

long l = 9876543210L;

List<int> list = //  how?

Expecetd result: [0,1,2,3,4,5,6,7,8,9] so list[0] will be 9, list[1] will be 8 (2nd digit from the left), etc.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
public static
  • 12,702
  • 26
  • 66
  • 86
  • 3
    **Compare this question to the original this one duplicates, which got four upvotes and an answer with 11 upvotes** – Robert Harvey Aug 26 '14 at 16:32
  • @RobertHarvey, I had some comments on my answer and now they are gone. Were they deleted by a mod? Is there some policy I'm unaware of? – Drew Noakes Aug 27 '14 at 13:41
  • @DrewNoakes: They were deleted by a mod. None of them were particularly relevant to your answer's content. – Robert Harvey Aug 27 '14 at 14:52

1 Answers1

2

If you're happy to do this via string processing, you could use:

long l = ...;

var list = l.ToString().Select(c => int.Parse(c.ToString())).ToList();

This converts the number to a string (in decimal), then parses each character in the string as an integer.

If performance is critical, you're better off doing this numerically.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742