/// <summary> /// Lambda that returns a list of minions that has the same strenght than the input parameter /// </summary> /// <param name="strength"></param> /// <returns></returns> public List <Minion> SearchByStrength(int strenght) { List <Minion> similarstrenght = new List <Minion>(); similarstrenght = Mylist.Where((Minion m) => m.StrenghtPoints == strenght).ToList(); if (similarstrenght.Count == 0) { similarstrenght = SortByStrength(strenght); } return(similarstrenght); }
/// <summary> /// Lambda expression that outputs a list of all name starting with a specific letter if no whole /// minionName was entered as it then returns that minions name instead /// </summary> /// <param name="name"></param> /// <returns></returns> public List <Minion> SearchNameByStartLetter(string searchfeature) { List <Minion> startsWith = new List <Minion>(); startsWith = Mylist.Where(x => (x.Name == searchfeature)).ToList(); if (startsWith.Count == 0) { char start = searchfeature.First <char>(); startsWith = Mylist.FindAll(x => (x.Name.StartsWith(start.ToString()))).ToList(); } return(startsWith); }
/// <summary> /// If no minion with the entered strenght are found and the entered value is not 0 /// evrything lower than the entered value are found, if no values lower than the entered value are found /// the function instead displays all values above it. /// </summary> private List <Minion> SortByStrength(int strinput) { List <Minion> SortByStrenght = new List <Minion>(); if (strinput > 0) { SortByStrenght = Mylist.Where(x => (x.StrenghtPoints < strinput)).ToList(); //below code is only run if if (SortByStrenght.Count == 0) { SortByStrenght = Mylist.Where(x => (x.StrenghtPoints > strinput)).ToList(); } } return(SortByStrenght); }
/// <summary> /// Lambda Function that filters through the list of minions to find those assigned a specific trait /// </summary> /// <param name="trait"></param> /// <returns></returns> public List <Minion> SearchByTrait(string trait) { List <Minion> minions = Mylist.Where(x => (x.Mylist.Contains(trait))).ToList(); return(minions); }
/// <summary> /// Lambda that returns a list of minions that is of the same type /// </summary> /// <param name="type"></param> /// <returns></returns> public List <Minion> SearchByType(MinionType type) { List <Minion> sameType = Mylist.Where((Minion m) => m.Specie == type).ToList(); return(sameType); }