C# Delegate & Event MCQs

Question 11: What will be the output of the following program?

static void Main()
{
    Func<string, string> greet = delegate (string name)
    {
        return "Hi " + name;
    };

    Console.Write(greet("Steve"));
}

Question 12: What will be the output of the following program?

static void Main(string[] args)
{
    Action<int> DoSomething = i => Console.Write(i);
    DoSomething(10);
}

Question 13: What will be the output of the following program?

public static void Main()
{
	Action DoSomething = () => Console.WriteLine("Hello!");
    DoSomething();
}

Question 14: What will be the output of the following program?

static void Main()
{
    Predicate<int> GetBool = delegate (int val)
    {
        if (val <= 0)
            return false;
        else
            return true;
    };
    Console.Write(GetBool(100));
} 

Question 15: What will be the output of the following program?

static void Main()
{
    Predicate GetBool = delegate()
    {
        return !true;

    };
    Console.Write(GetBool(100));
} 

Question 16: What will be the output of the following program?

public delegate void Print(int value);

static void Main(string[] args)
{
    Print print = delegate(int val) { 
        Console.WriteLine("Value: {0}", val); 
    };

    print(50);
}

Question 17: Which of the following statement(s) are TRUE?