Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bill
- {
- private string billNumber;
- private string billDate;
- private DateTime date;
- private string from;
- private string to;
- private string billCost;
- private string power1;
- private string power2;
- private string power3;
- private string power4;
- private string power5;
- private string power6;
- private string contractNumber;
- }
- class Contract
- {
- private List<Bill> billList;
- private Dictionary<double, Bill> billsDictionary;
- private double contractNumber;
- }
- class Pet
- {
- public string Name { get; set; }
- public int Age { get; set; }
- }
- public static void OrderByEx1()
- {
- Pet[] pets = { new Pet { Name="Barley", Age=8 },
- new Pet { Name="Boots", Age=4 },
- new Pet { Name="Whiskers", Age=1 } };
- IEnumerable<Pet> query = pets.OrderBy(pet => pet.Age);
- foreach (Pet pet in query)
- {
- Console.WriteLine("{0} - {1}", pet.Name, pet.Age);
- }
- }
- /*
- This code produces the following output:
- Whiskers - 1
- Boots - 4
- Barley - 8
- */
- public class Comp : IComparer<Bill>
- {
- public int Compare(Bill x, Bill y)
- {
- // remember to handle null values first (x or y or both are nulls)
- return x.date.CompareTo(y.date);
- }
- }
- billList.Sort(new Comp());
- billList = billList.OrderBy(bill => bill.date).ToList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement