csharp Delegate & Event Questions & Answers

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();
}
ADVERTISEMENT

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));
}