How can I sort the file txt line 5000000?

c#, sorting

Solution

var result = File.ReadAllLines("...filepath...")
                 .Select(line => line.Split(','))
                 .Select(parts => new
                 {
                     V1 = int.Parse(parts[0]),
                     V2 = int.Parse(parts[1])
                 })
                 .OrderBy(v => v.V1)
                 .ThenBy(v => v.V2)
                 .ToList();

Duplicates will be handled properly by default. If you want to remove them, add `.Distinct()` somewhere, for example after `ReadAllLines`.

Problem

i've got a disordered file with 500000 line which its information and date are like the following : ``` for instance desired Result ------------ --------------- 723,80 1,4 14,50 1,5 723,2 10,8 1,5 14,50 10,8 723,2 1,4 723,80 ``` Now how can i implement such a thing ? I've tried the sortedList and sorteddictionary methods but there is no way for implemeting a new value in the list because there are some repetative values in the list. I'd appreciate it if u suggest the best possible method . One more thing , i've seen this question but this one uses the class while i go with File! C# List<> Sort by x then y

Original source

Related problems