public static void Test5() { var students = HardCodeStudents(); // Split collection of Student to sub-collections of Student (IEnumerable<IGrouping<int, T>> where T : Student) // with normal method var result = LINQWorks.StudentsByGroups(students); result .ForEach(x => { Console.WriteLine($"Group: {x.Key}"); x.ForEach(y => Console.WriteLine($"{y.FullName}")); }); PrintLine(); // with ext method students .StudentsByGroups() .ForEach(x => { Console.WriteLine($"Group: {x.Key}"); x.ForEach(y => Console.WriteLine($"{y.FullName}")); }); PrintLine(); }
// every method from group have comments what exactly testing - just separated to be easier to check results public static void Test() { var students = HardCodeStudents(); // students whos first name lexicographically before last // with ext method var result = students.FirstBeforeLast(); result.ForEach(x => Console.WriteLine(x.FullName)); PrintLine(); // with normal method result = LINQWorks.FirstBeforeLast(students); result.ForEach(x => Console.WriteLine(x.FullName)); PrintLine(); // students in age range 18-25 including // with ext method var otherResult = students.InAgeRange(18, 25); otherResult.ForEach(x => Console.WriteLine(x)); PrintLine(); // with normal method otherResult = LINQWorks.InAgeRange(students, 18, 25); otherResult.ForEach(x => Console.WriteLine(x)); PrintLine(); // sorted students lexicographically by decending first name - then by last name // with ext method result = students.StudentsSort(); result.ForEach(x => Console.WriteLine(x.FullName)); PrintLine(); // with normal method result = LINQWorks.StudentsSort(students); result.ForEach(x => Console.WriteLine(x.FullName)); PrintLine(); // print numbers once to be seen easy var numbers = new[] { 4, 19, 21, 144, 48, 84, 96, 12, 7, 100, 0, 13, -5, 12, 3, 7 }; PrintNumbers(numbers); // print numbers from array that can be devided by 3 AND 7 without reminder (can be changed to OR easy) // with ext method var numResult = numbers.DividebleByTwentyOne(); PrintNumbers(numResult); // with normal method numResult = LINQWorks.DividebleByTwentyOne(numResult); PrintNumbers(numResult); }
public static void Test2() { var students = HardCodeStudents(); // students from group 2 // with ext method students .StudentsFromGroup(2) .OrderBy(x => x.FirstName) .ForEach(x => Console.WriteLine($"{x.FullName} group: {x.GroupNumber}")); PrintLine(); // with normal method var result = LINQWorks.StudentsFromGroup(students, 2); result .OrderBy(x => x.FirstName) .ForEach(x => Console.WriteLine($"{x.FullName} group: {x.GroupNumber}")); PrintLine(); // students with specific domain // with ext method students .StudentsByMailDomain("abv.bg") .ForEach(x => Console.WriteLine($"{x.FullName} mail: {x.Mail}")); PrintLine(); // with normal method result = LINQWorks.StudentsByMailDomain(students, "abv.bg"); result .ForEach(x => Console.WriteLine($"{x.FullName} mail: {x.Mail}")); PrintLine(); // students with phone in Sofia (+359 2 xxx xxxx) but let say all from Bulgaria so i dont check for +359 exactly // with ext method students .StudentsByPhone(2, "2") .ForEach(x => Console.WriteLine($"{x.FullName} tel.: {x.Tel}")); PrintLine(); // with normal method result = LINQWorks.StudentsByPhone(students, 2, "2"); result .ForEach(x => Console.WriteLine($"{x.FullName} tel.: {x.Tel}")); PrintLine(); }