Hi
With this code, i get first Bob, then Bill. So it doesn't sort the data. I found the solution (see below) but i want to know where is the error here, why it doesn't work.
Thanks
V
using System;
using System.Collections.Generic;
using System.Linq;
class MyClass
{
public string Naam;
public int Age; publuc string Country; }
List
t.Add(new MyClass() { Name = "Bob", Age = 36, Cuntry = "UK" });
t.Add(new MyClass() { Name = "Bill", Age = 32, Country = "USA" });
.OrderBy(x => x.Age);
foreach (MyClass x in t)
Console.Write(x.Name + " " + x.Country + ", " + x.Age);
But with this code, it works:
var sort1 = t.OrderBy(x => x.Age);
foreach (var x in sort1)
Console.Write(x.Name + " " + x.Age;

Vishal YelveRank #178 · 13.6K reputationPosted Aug 22, 2022, 10:26 AM EDT
Vishal JoshiRank #377 · 6.7K reputationPosted Aug 23, 2022, 2:37 AM EDT
Valerie MeunierRank #1,526 · 1K reputationPosted Aug 23, 2022, 5:10 AM EDT
Vishal JoshiRank #377 · 6.7K reputationPosted Aug 23, 2022, 6:04 AM EDT
Valerie MeunierRank #1,526 · 1K reputationPosted Aug 23, 2022, 8:53 AM EDT