Test-NetConnection -Port 801 -ComputerName 192.168.1.1 -InformationLevel Detailed
Friday, May 15, 2020
Friday, May 8, 2020
LINQ, LAMBDA - Example of Difference between Select and SelectMany
using System; using System.Linq; class School { public string Name{get; set;} public Student[] Students{get;set;} } class Student { public string Name {get;set;} } public class Program { public static void Main() { var schools = new [] { new School(){Name ="Harvard", Students = new [] { new Student(){ Name="Bob"}, new Student(){ Name="Jack"} }}, new School(){Name ="Stanford", Students = new [] { new Student(){ Name="Jim"}, new Student(){ Name="John"} }} }; //Select Many var allStudents = schools.SelectMany(s=> s.Students); Console.WriteLine("Results with one loop and SelectMany\n"); foreach(var student in allStudents){ Console.WriteLine(student.Name); } // Select var mySchool = schools.Select(s => s.Students); Console.WriteLine("Results with two loops and Select\n"); foreach(var school in mySchool){ foreach(var studentd in school){ Console.WriteLine(studentd.Name); } } } }
Subscribe to:
Posts (Atom)