Tulika Kumar

Tulika Kumar

  • 1.7k
  • 14
  • 20.9k

Sorting of a List of Objects

Jan 11 2013 6:27 PM
I have a class named: Product

  public class Product
  {
  string name;
  public string Name { get { return name; } }
  double price;
  public double Price { get { return price; } }
  string location;
  public string Location { get { return location; } }
  public Product(string name, double price, string location)
  {
  this.name = name;
  this.price = price;
  this.location = location;
  }
  }
Now I created a list of Product object
 List<Product> lstProduct = new List<Product>{
  new Product("WWW", 9.99, "ZZZZZZZZZ"),
  new Product("AAA", 14.99, "RRRRRRRR"),
  new Product("AAA", 12.99, "AAAAAAA"),
  new Product("GGG", 13.69, "WWWWWWWWWWWWWWW"),
  new Product("GGG", 13.99, "NNNNNNNN"),
  new Product("KKK", 10.99, "TTTTTTTTTTTTTTTT")
  };

Then, I need to sort them firstly by Name and then bind into a DataGrid.
Thanks in advance

Answers (3)