static void Main(string[] args) { //Create a Fox class with 3 properties(name, type, color) Fill a list with at least 5 foxes, //it's up to you how you name/create them! Write a LINQ Expression to find the foxes with green color! //Write a LINQ Expression to find the foxes with green color and pallida type! Fox one = new Fox("Nick Wilde", "macrotis", "green"); Fox two = new Fox("Robin Hood", "pallida", "grey"); Fox three = new Fox("Eevee", "corsac", "green"); Fox four = new Fox("ninetails", "pallida", "green"); Fox five = new Fox("swiper", "totoro", "white"); List <Fox> cohort = new List <Fox> { one, two, three, four, five }; var GreenFoxes = cohort.Where(fox => fox.Color.Equals("green")); var GreenAndPallida = GreenFoxes.Where(fox => fox.Type.Equals("pallida")); foreach (var fox in GreenFoxes) { Console.WriteLine($"{fox.Name} is a {fox.Color} {fox.Type} type fox"); } Console.WriteLine(); foreach (var fox in GreenAndPallida) { Console.WriteLine($"{fox.Name} is a {fox.Color} {fox.Type} type fox"); } Console.ReadLine(); }
public void FoxGreenAndPallida(List <Fox> input) { var greenPallida = from fox in input where fox.Color == "green" && fox.Type == "pallida" select fox.Name; foreach (var Fox in greenPallida) { Console.WriteLine("The fox named {0} is green and pallida.", Fox.ToString()); } }
public void FindGreenFoxes(List <Fox> input) { var greenFox = from greenfox in input where greenfox.Color == "green" select greenfox.Name; foreach (var Fox in greenFox) { Console.WriteLine("The fox named {0} is green.", Fox.ToString()); } }
static void Main(string[] args) { //Create a Fox class with 3 properties(name, type, color) Fill a list with at least 5 foxes, //it's up to you how you name/create them! Write a LINQ Expression to find the foxes with green color! //Write a LINQ Expression to find the foxes with green color and pallida type! var listOfFoxes = new List <Fox>(); var fox1 = new Fox("Alpaga", "green", "pallida"); var fox2 = new Fox("Oracle", "green", "pallida"); var fox3 = new Fox("Rabbit", "green", "pallida"); var fox4 = new Fox("Totoro", "green", "static"); var fox5 = new Fox("FutureFox", "yellow", "FutureType"); listOfFoxes.Add(fox1); listOfFoxes.Add(fox2); listOfFoxes.Add(fox3); listOfFoxes.Add(fox4); listOfFoxes.Add(fox5); QuerySyntaxForGreenFoxes(listOfFoxes); QuerySyntaxForGreenFoxesAndPallida(listOfFoxes); MethodSyntaxForGreenFoxes(listOfFoxes); MethodSyntaxForGreenFoxesAndPallida(listOfFoxes); Console.ReadLine(); }
static void Main(string[] args) { var pack = new Pack(); var fox = new Fox("Vuk", "pallida", "red"); pack.foxes.Add(fox); var fox2 = new Fox("Karak", "sarki", "white"); pack.foxes.Add(fox2); var fox3 = new Fox("Bobby", "ezust", "grey"); pack.foxes.Add(fox3); var fox4 = new Fox("Teddy", "pallida", "green"); pack.foxes.Add(fox4); var fox5 = new Fox("Lauren", "pallida", "green"); pack.foxes.Add(fox5); pack.FindGreenFoxes(pack.foxes); pack.FoxGreenAndPallida(pack.foxes); Console.ReadLine(); }