-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.

3
  • 3
    Compare this question to the original this one duplicates, which got four upvotes and an answer with 11 upvotes Aug 26, 2014 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? Aug 27, 2014 at 13:41
  • @DrewNoakes: They were deleted by a mod. None of them were particularly relevant to your answer's content. Aug 27, 2014 at 14:52

1 Answer 1

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.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.