Qtr No. 213, New Town Yehlanka Indore 454775
Consider the following code snippet:
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Department { get; set; }
}
static void Main(string[] args)
{
List<Employee> empTree = new List<Employee>();
empTree.Add(new Employee { FirstName = "James", LastName = "Cameroon", Department = "IT" });
empTree.Add(new Employee { FirstName = "Tom", LastName = "Hanks", Department = "Marketing" });
empTree.Add(new Employee { FirstName = "Brad", LastName = "Pitt", Department = "IT" });
empTree.Add(new Employee { FirstName = "Tom", LastName = "Cruise", Department = "Sales" });
empTree.Add(new Employee { FirstName = "Angelina", LastName = "Jolie", Department = "Sales" });
empTree.Add(new Employee { FirstName = "Leonardo", LastName = "DiCaprio", Department = "Marketing" });
// LINQ query missing here
foreach (var dept in employeesByDept)
{
Console.WriteLine("Department: {0}", dept.Key);
foreach (var emp in dept)
{
Console.WriteLine("\t{0} {1}", emp.FirstName, emp.LastName);
}
}
}
What is the appropriate LINQ query to be written inside the Main() method, to produce the following output?
var employeesByDept = from e in empTree group e by e.Department;
var employeesByDept = from e in empTree group e by e.FirstName;
var employeesByDept = from e in empTree group e.Department;
var employeesByDept = from e in Employee group e by e.Department;
To get all Advanced CSharp Programming Assessment Exam questions Join Group https://bit.ly/infy_premium_group
We're passionate about offering best placement materials and courses!! A one stop place for Placement Materials. We daily post Offcampus updates and Placement Materials.
Qtr No. 213, New Town Yehlanka Indore 454775
admin@prepflix.in