0

I have a list created from a log file and I need to sort it.

I have tried list.OrderBy() but it gives me errors and is not working.

List<string[]> list = new List<string[]>();
var logFile = File.ReadAllLines(Name1);
foreach (var item in logFile)
{
   list.Add(new string[] { date_check(item), time_check(item),logType(item), device(item), rest(item) });
}

I need to sort this list by date and time. How can I do it?

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
DanH.
  • 53
  • 1
  • 7

2 Answers2

3

you can try like this

 var sortList = list.OrderBy(a => a.date_check).ThenBy(a => a.time_check).ToList();
Vinoth
  • 851
  • 7
  • 23
  • i get this error : Severity Code Description Project File Line Suppression State Error CS1061 'string[]' does not contain a definition for 'date_check' and no extension method 'date_check' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?) Logs Analizer C:\Users\HajduSl\source\repos\Logs Analizer\Logs Analizer\LogFileView.cs 31 Active – DanH. Dec 28 '18 at 04:52
  • found it : var sortList = list.OrderBy(arr => arr[0]).ThenBy(arr => arr[1]).ToList(); – DanH. Dec 28 '18 at 04:56
0

acording to Vinoth answer this one worked for me:

var sortList = list.OrderBy(arr => arr[0]).ThenBy(arr => arr[1]).ToList();
DanH.
  • 53
  • 1
  • 7