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"};
bool fruitsFruits2AreEqual = fruits.SequenceEqual(fruits2);
Console.WriteLine("The fruits and fruits2 arrays {0} equal to each other.", fruitsFruits2AreEqual ? "are" : "are not");
string[] otherLargeFruits = {"watermelon", "papaya", "dragonfruit", "jackfruit"};
bool largeFruitCompare = largeFruits.SequenceEqual(otherLargeFruits);
Console.WriteLine("The largeFruits and otherLargeFruits arrays {0} equal to each other.", largeFruitCompare ? "are" : "are not");
Pet chuck = new Pet { Name = "Charles", Age = 6 };
Pet pete = new Pet { Name = "Pete", Age = 2 };
Pet alsoCharles = new Pet { Name = "Charles", Age = 6 };
List<Pet> twoChuck1 = new List<Pet>();
List<Pet> twoChuck2 = new List<Pet>();
bool twoChuckEqual = twoChuck2.SequenceEqual(twoChuck1);
Console.WriteLine("twoChuckEqual: " + twoChuckEqual);
List<Pet> chuckAndCharles1 = new List<Pet>();
chuckAndCharles1.Add(chuck);
chuckAndCharles1.Add(new Pet("Pete", 2));
List<Pet> chuckAndCharles2 = new List<Pet>();
chuckAndCharles2.Add(alsoCharles);
chuckAndCharles2.Add(pete);
bool chuckAndCharlesEqual = chuckAndCharles1.SequenceEqual(chuckAndCharles2);
Console.WriteLine("chuckAndCharlesEqual: " + chuckAndCharlesEqual);
bool chuckAndCharlesEqualWithIEqualityComparer = chuckAndCharles1.SequenceEqual(chuckAndCharles2, new PetComparer());
Console.WriteLine("chuckAndCharlesEqualWithIEqualityComparer: " + chuckAndCharlesEqualWithIEqualityComparer);
Console.WriteLine("---");
Pet pet1 = new Pet { Name = "Turbo", Age = 2 };
Pet pet2 = new Pet { Name = "Peanut", Age = 8 };
List<Pet> pets1 = new List<Pet> { pet1, pet2 };
List<Pet> pets2 = new List<Pet> { pet1, pet2 };
bool equal = pets1.SequenceEqual(pets2);
equal ? "are" : "are not");
Pet pet1m = new Pet() { Name = "Turbo", Age = 2 };
Pet pet2m = new Pet() { Name = "Peanut", Age = 8 };
List<Pet> pets1m = new List<Pet> { pet1, pet2 };
new List<Pet> { new Pet { Name = "Turbo", Age = 2 },
new Pet { Name = "Peanut", Age = 8 } };
bool equalM = pets1m.SequenceEqual(pets2m);
Console.WriteLine("The m lists {0} equal.", equalM ? "are" : "are not");
Product msOrange = new Product("orange", 4);
List<Product> storeA = new List<Product> { new Product { Name = "apple", Code = 9 },
new Product { Name = "orange", Code = 4 } };
List<Product> storeB = new List<Product> { new Product { Name = "apple", Code = 9 }};
bool equalAB = storeA.SequenceEqual(storeB, new ProductComparer());
Console.WriteLine("StoreA and StoreB Equal? " + equalAB);
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;