-4

I've seen similar posts, but can't find anything that gives me an answer for my case

string[] entries = File.ReadAllLines();
var orderedEntries = entries.OrderByDescending(x => int.Parse(x.Split(" ")[1]));
foreach (var entry in orderedEntries.Take(5))
{
    Console.WriteLine(entry);
}

The error seems to be with this line:

var orderedEntries = entries.OrderByDescending(x => int.Parse(x.Split(" ")[1]));

It says the it cannot convert from "string" to "char" which I'm assuming it means that it can only split by a character, is there a way I can change this to allow for the space I want whilst still keeping it having the same function.

*Edit, I didn't mean to have this as a duplicate, I didn't know that a "Delimiter" even was let alone that it was part of my problem. Apologies for wasting your time.

1 Answers1

1

Change this

var orderedEntries = entries.OrderByDescending(x => int.Parse(x.Split(" ")[1]));

to this

var orderedEntries = entries.OrderByDescending(x => int.Parse(x.Split(' ')[1]));
Lews Therin
  • 3,707
  • 2
  • 27
  • 53