using System.Collections.Generic;
public static void Main()
int[] awesomeNumbers = {4,2,49,21,92,39,10,08,73,94,81,95,14};
string[] emptyBasket = {};
string[] fruits = {"apple", "mango", "yakfruit", "canneryfruit", "orange", "passionfruit", "grape", "pear"};
string[] fruits2 = {"apple", "yakfruit", "orange", "grape", "pear", "watermelon"};
string[] largeFruits = {"watermelon", "papaya", "dragonfruit", "jackfruit"};
string[] grape = {"grape"};
List<Tenant> allTenants = new List<Tenant>();
Tenant Jash = new Tenant("Jash", 2, new List<Pet>{
new Pet{Name = "Bonkers", Age = 3}
Tenant Dave = new Tenant("Dave", 1, new List<Pet>{
new Pet{Name = "Tim", Age = 34},
new Pet{Name = "Smedge", Age = 2},
Tenant Samantha = new Tenant("Samantha", 1, new List<Pet>{
new Pet{Name = "Rex Goliath", Age = 6}
Tenant Poti = new Tenant("Poti", 1, new List<Pet>{
new Pet{Name = "Jem", Age = 2},
new Pet{Name = "Egg", Age = 23},
new Pet{Name = "Fluffy the Warrior", Age = 9}
allTenants.Add(Samantha);
IEnumerable<Tenant> firstBuildingThenPetCount = allTenants.OrderBy(thisTenant => thisTenant.BuildingNumber).ThenBy(thisTenant => thisTenant.PetList.Count);
foreach (Tenant tenant in firstBuildingThenPetCount){
Console.WriteLine(tenant.Name);
Console.WriteLine(" --Pets: " + String.Join(" | ", tenant.PetList.Select(thisPet => thisPet.Name + "(" + thisPet.Age + ")") ));
IEnumerable<string> weirdFruitOrder = fruits.OrderBy(thisFruit => thisFruit.Last()).ThenByDescending(thisFruit => thisFruit.Length);
Console.WriteLine("fruits by their last letter then by length, longest first");
Console.WriteLine("Fruits: " + String.Join(" ", weirdFruitOrder));
Console.WriteLine("---");
string[] MSfruits = { "grape", "passionfruit", "banana", "mango",
"orange", "raspberry", "apple", "blueberry" };
IEnumerable<string> query =
MSfruits.OrderBy(fruit => fruit.Length).ThenBy(fruit => fruit);
foreach (string fruit in query)
Console.WriteLine(fruit);
public string Name { get; set; }
public List<string> Pets { get; set; }
public string Name{ get; set;}
public int Age{ get; set;}
public Pet(string n, int a){
public class PetComparer : IEqualityComparer<Pet>
public bool Equals(Pet x, Pet y){
if (Object.ReferenceEquals(x, y)) return true;
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return x.Name == y.Name && x.Age == y.Age;
public int GetHashCode(Pet pet){
if (Object.ReferenceEquals(pet, null)) return 0;
int hashProductName = pet.Name == null ? 0 : pet.Name.GetHashCode();
int hashProductAge = pet.Age.GetHashCode();
return hashProductName ^ hashProductAge;
public string Name{ get; set;}
public string Address{ get; set;}
public int Number{ get; set;}
public Building(string name, string addy, int num){
public string Name{ get; set;}
public int BuildingNumber{ get; set;}
public List<Pet> PetList{get; set;}
public Tenant(string name, int BN){
this.BuildingNumber = BN;
this.PetList = new List<Pet> {};
public Tenant(string name, int BN, List<Pet> PL){
this.BuildingNumber = BN;
public string Name { get; set; }
public int Code { get; set; }
public Product(string n, int c){
class ProductComparer : IEqualityComparer<Product>
public bool Equals(Product x, Product y)
if (Object.ReferenceEquals(x, y)) return true;
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return x.Code == y.Code && x.Name == y.Name;
public int GetHashCode(Product product)
if (Object.ReferenceEquals(product, null)) return 0;
int hashProductName = product.Name == null ? 0 : product.Name.GetHashCode();
int hashProductCode = product.Code.GetHashCode();
return hashProductName ^ hashProductCode;