How to generate a list of lists of digits?

Another option... var data = Enumerable. Range(0, 10000) . Select(x => new List { x / 1000, (x / 100) % 10, (x / 10) % 10, x % 10 }) .ToList(); And if you want to generate an arbitrary number of digits you can do something like this: int n = 4; // number of digits var data = Enumerable.

Range(0, (int)Math. Pow(10, n)) . Select(x => Enumerable.

Range(1, n) . Select(y => (x / (int)Math. Pow(10, n - y)) % 10) .ToList()) .ToList().

I like this one, it's inventive! – Shimrod Jan 26 '11 at 10:25 Is it possible to make the length of the inner list depends on the global constan N? Such as in my case, I set N to 4.

– xport Jan 26 '11 at 10:34 @xport: Yep, I'll update the answer to demonstrate... – LukeH Jan 26 '11 at 10:42 Excellent! Thank you very much. – xport Jan 26 '11 at 11:01.

Try this. Var numbers = Enumerable. Range(0, 10); var data = (from a in numbers from be in numbers from c in numbers from d in numbers select new List() { a, b, c, d }).ToList().

2 You can also use Range to create numbers: var numbers = Enumerable. Range(0, 10); – vc 74 Jan 26 '11 at 10:04 @vc 74: Of course, I will edit my answer. Thank you.

– Matajon Jan 26 '11 at 10:08 thanks for your answer. – xport Jan 26 '11 at 10:16.

Since you know the size of the list in advance, I would prefer a native two dimensional array. The code would look like this: var data = new int10000, 4; for (int I = 0; I.

Simple and 'dumb' solution: List> data = new List>(); int i; int k; int l; int m; for(i=0; i); datai. Add(i); for(k=0; kAdd(l); for(m=0; m.

Just tried to answer the question in the way I understood it?! – chiffre Jan 26 '11 at 10:07 1 Wasn't me :-) but notice (for one thing) that you produce 10 lists, answer should produce 10,000 lists – Oren A Jan 26 '11 at 10:09 oh I see - damn... – chiffre Jan 26 '11 at 10:24.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions