The cause is neither IEnumerable
nor IOrderedEnumerable
support indexing, showing you the error.
To display the ordered result you can use foreach
to enumerate the collection:
// display the newly ordered list
foreach (var user in usersByUsername)
{
Console.WriteLine(string.Join(", ", user));
}
Or you can convert result to list and use indexing:
//sort this list by username ascending
IList<String[]> usersByUsername = users.OrderBy(user => user[0]).ToList();
// display the newly ordered list
for (int i = 0; i <= users.Count; i++)
{
Console.WriteLine(string.Join(", ", usersByUsername[i]));
}
Also note the usage of string.Join
- just printing string[]
might not give you the result you expect.