score:2

I do not see how your class MeasureStation will ever work

What is _measureStation, is it this?

If it is, Then it should look like, note that the property cannot have the same name as its respective private member

  public class MeasureStation
  {
    private int id;//private is optional as it is default
    public int ID
    {
      get { return this.id; }
      set { this.id = value; }
    }
    private String name;//private is optional as it is default
    public String Name
    {
      get { return this.name; }
      set { this.name = value; }
    }
  }

Though, it is equivalent to the class with auto-properties:

public class MeasureStation
{
  public int ID {get;set;}
  public String Name {get;set;}
}

So, I run against both of them

private static void Main(string[] args)
{
  List<MeasureStation> itemsToSort
    = new List<MeasureStation>()
        {
          new MeasureStation() {ID = 01, Name = "Bbbb"},
          new MeasureStation() {ID = 01, Name = "Aaaa"},
          new MeasureStation() {ID = 01, Name = "Cccc"}
        };
  List<MeasureStation> sortedItems = itemsToSort.OrderBy(x => x.Name).ToList();

  Console.WriteLine("******itemsToSort*****");
  foreach (var item in itemsToSort)
      Console.WriteLine(item.Name.ToString());

  Console.WriteLine("******sortedItems*****");
  foreach (var item in sortedItems)
        Console.WriteLine(item.Name.ToString());

  Console.ReadLine();
}

having gotten ordered output:

******itemsToSort*****
Bbbb
Aaaa
Cccc
******sortedItems*****
Aaaa
Bbbb
Cccc

Related Articles