Click here to Skip to main content
15,843,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have list(A) of 2,30,000 items where 1st item in list is (3,1110000000) here in this example 3 is sum of number 1110000000. and I sorted this list in descending order according to sum and now my 1st item is (57,9657551955). now there are many numbers whose sum is 57 and so on then dump all numbers whose sum is 57 into a file named "57.CSV" and so on. now after sorting the list in descending order I found 57 sum from 0th index to 121th index , 56 sum from 122th index to 178th index. Now i want to create lists from list(A) for all sums 57 , 56 and so on. How to do this?

Please suggest.

What I have tried:

using (StreamReader sr = new StreamReader(fs))
                    {
                        string barcode_data = sr.ReadToEnd().Replace("\r\n", ",");
                        string[] Allbarcodes = barcode_data.Split(',');
                        int counter = 0;

                        for (int i = 0; i < Allbarcodes.Length - 1; i++)
                        {
                            if (!string.IsNullOrEmpty(Allbarcodes[i]))
                            {
                                long sumOfnum = Summation(Convert.ToInt64(Allbarcodes[i]));
                                barcodeList.Add(sumOfnum + "," + Allbarcodes[i]);
                            }
                        }
                        Array.Clear(Allbarcodes, 0, Allbarcodes.Length);
                        label1.Text = counter++.ToString();

                        result = barcodeList.Select(m => new { value = int.Parse(m.Substring(0, m.IndexOf(','))), item = m }).
                                     OrderByDescending(m => m.value).Select(m => m.item).ToList();
////list result contains all items and have to make sublists of it//// 
                        sr.Close();
                        sr.Dispose();
                    }
Posted
Updated 1-Mar-17 1:48am
v2

 
Share this answer
 
v2
Comments
Graeme_Grant 1-Mar-17 6:49am    
You sneaked under me ... good to see that we both had the same answer. ;)
OriginalGriff 1-Mar-17 7:40am    
It's the obvious solution - I added a bit on grouping the results into a dictionary as well.
Graeme_Grant 1-Mar-17 7:44am    
yes, that can be a challenge for a newbie...
Linq's GroupBy I think would do what you want.
How to: Group Query Results (C# Programming Guide)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900