.Net > Beginner

What would be the output of the following code using lookup on a List?

using System;
using System.Collections.Generic;
using System.Linq;

class MyClass
{
    public string Name { get; set; }
    public int Age { get; set; }
}
class Program
{
    static MyClass GetNewMyClassObject(string name, int age)
    {
        MyClass mObj = new MyClass();
        mObj.Name = name;
        mObj.Age = age;
        return mObj;
    }
    static void Main()
    {
        List<MyClass> listObj = new List<MyClass>();
        listObj.Add(GetNewMyClassObject("Manoj", 29));
        listObj.Add(GetNewMyClassObject("Sumit", 30));


        var lookup = listObj.ToLookup(o => o.Age);
        foreach (MyClass m in lookup[29])
        {
            Console.Write("29" + m.Name);
        }
        foreach (MyClass m in lookup[29])
        {
            Console.Write("30" + m.Name);
        }
        Console.ReadLine();
    }
}
Answers :
Time Left
Question Number : /20
Please do not press back or refresh button during this test.

Login

Register

Next Question