My Report

C# Delegate Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following C# code?

{
 delegate string f(string str);
 class sample
 {
     public static string fun(string a)
     {
         return a.Replace('k', 'o');
     }
 }
 class Program
 {
     static void Main(string[] args)
     {
         f str1 = new f(sample.fun);
         string str = str1("Test Ykur C#.NET Skills");
         Console.WriteLine(str);
         Console.ReadLine();
     }
 }
}

2. What will be the output of the following C# code snippet?

{
    delegate void A(ref string str);
    class sample
    {
        public static void fun( ref string a)
        {
            a = a.Substring( 7, a.Length - 7);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            A str1;
            string str = "Test Your C#.net skills";
            str1 = sample.fun;
            str1(ref str);
            Console.WriteLine(str);
        }
    }
}

3. Which of the following are the correct statements about delegates?

4. Choose the correct way to call subroutine fun() of the sample class?

class a
{
    public void x(int p, double k)
    {
        Console.WriteLine("k : csharp!");
    }
}

5. Which of the following is the correct way to call the function abc() of the given class in the following C# code?

class csharp
{
    public int abc(int a)
    {
        Console.WriteLine("A:Just do it!");
        return 0;
    }
}

6. Which of the following is the correct way to call the subroutine function abc() of the given class in the following C# code?

class csharp
{
    void abc()
    {
        console.writeline("A:Just do it!");
    }
}

7. What will be the output of the following C# code snippet?

{
    delegate string F(string str);
    class sample
    {
        public static string fun(string a)
        {
            return a.Replace(',''-');
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            F str1 = new F(sample.fun);
            string str = str1("Test Your c#.NET skills");
            Console.WriteLine(str);
        }
    }
}

8. Choose the statements which makes delegate in C#.NET different from a normal class?

9. Incorrect statements about delegates are?

10. Select the modifiers which control the accessibility of the delegate?


 

Start practicing “1000 MCQs on C#”, and once you are ready, you can take tests on all topics by attempting our “C# Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.