MartisK

Untitled

Oct 14th, 2020
636
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public List<Car> FindNewestCars()
  2. {
  3.     List<Car> result = new List<Car>();
  4.     DateTime latestDate = allCars[0].BuiltDate;
  5.  
  6.     foreach (var car in allCars)
  7.     {
  8.         if (DateTime.Compare(latestDate, car.BuiltDate) > 0)
  9.         {
  10.             latestDate = car.BuiltDate;
  11.         }
  12.     }
  13.  
  14.     foreach (var car in allCars)
  15.     {
  16.         if (DateTime.Compare(latestDate, car.BuiltDate) == 0)
  17.         {
  18.             result.add(car);
  19.         }  
  20.     }
  21.  
  22.     return result;
  23. }
RAW Paste Data