250+ TOP MCQs on Delegates in Detail and Answers

This set of Basic C# Questions and Answers on “Delegates in Detail”.

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

  1. class a
  2. {
  3.     public void x(int p, double k)
  4.     {
  5.         Console.WriteLine("k : csharp!");
  6.     }
  7. }

a)

   delegate void del(int i);
   x s = new x();
   del d = new del(ref s.x);
   d(8, 2.2f);

b)

   delegate void del(int p,  double k);
   del d;
   x s = new x();
   d = new del(ref s.x);
   d(8, 2.2f);

c)

   x s = new x();
   delegate void d = new del(ref x);
   d(8, 2.2f);

d) all of the mentioned

Answer: b
Clarification: None.

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

  1. class csharp
  2. {
  3.     public int abc(int a)
  4.     {
  5.         Console.WriteLine("A:Just do it!");
  6.         return 0;
  7.     }
  8. }

a)

   delegate void del(int a);
   csharp s = new csharp();
   del d = new del(ref s.abc);
   d(10);

b)

   csharp s = new csharp();
   delegate void d = new del(ref abc);
   d(10);

c)

   delegate int del(int a);
   del d;
   csharp s = new csharp();
   d = new del(ref s.fun);
   d(10);

d) none of the mentioned

Answer: c
Clarification: None.

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

  1. class csharp
  2. {
  3.     void abc()
  4.     {
  5.         console.writeline("A:Just do it!");
  6.     }
  7. }

a)

   csharp c = new csharp();
   delegate void d = new del(ref abc);
   d();

b)

   delegate void del();
   del d;
   csharp s = new csharp();
   d = new del(ref s.abc);
   d();

c)

   csharp s = new csharp();
   delegate void del = new delegate(ref abc);
   del();

d) None of the mentioned

Answer: b
Clarification: None.

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

  1. {
  2.     delegate void A(ref string str);
  3.     class sample
  4.     {
  5.         public static void fun( ref string a)
  6.         {
  7.             a = a.Substring( 7, a.Length - 7);
  8.         }
  9.     }
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             A str1;
  15.             string str = "Test Your C#.net skills";
  16.             str1 = sample.fun;
  17.             str1(ref str);
  18.             Console.WriteLine(str);
  19.         }
  20.     }
  21. }

a) Test Your
b) ur C#.NET
c) ur C#.NET Skills
d) None of the mentioned

Answer: c
Clarification: None.

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

  1. {
  2.     delegate string F(string str);
  3.     class sample
  4.     {
  5.         public static string fun(string a)
  6.         {
  7.             return a.Replace(',''-');
  8.         }
  9.     }
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             F str1 = new F(sample.fun);
  15.             string str = str1("Test Your c#.NET skills");
  16.             Console.WriteLine(str);
  17.         }
  18.     }
  19. }

a) Test Your
b) Test-Your-C#.NET-Skills
c) ur C#.NET Skills
d) None of the mentioned

Answer: b
Clarification: None.
Output:

6. Choose the statements which makes delegate in C#.NET different from a normal class?
a) Delegates in C#.NET is a base class for all delegates type
b) Delegates created in C#.NET are further not allowed to derive from the delegate types that are created
c) Only system and compilers can derive explicitly from the Delegate or MulticasteDelegate class
d) All of the mentioned

Answer: d
Clarification: None.

7. Which of the following are the correct statements about delegates?
a) Delegates can be used to implement callback notification
b) Delegates permit execution of a method on a secondary thread in an asynchronous manner
c) Delegate is a user defined type
d) All of the mentioned

Answer: d
Clarification: None.

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

  1. {
  2.  delegate string f(string str);
  3.  class sample
  4.  {
  5.      public static string fun(string a)
  6.      {
  7.          return a.Replace('k', 'o');
  8.      }
  9.  }
  10.  class Program
  11.  {
  12.      static void Main(string[] args)
  13.      {
  14.          f str1 = new f(sample.fun);
  15.          string str = str1("Test Ykur C#.NET Skills");
  16.          Console.WriteLine(str);
  17.          Console.ReadLine();
  18.      }
  19.  }
  20. }

a) Test Ykur C#.NET Skills
b) Test Ykour C#.NET Skills
c) Test Your C#.NET Skills
d) Test ur C#.NET Skills

Answer: c
Clarification: None.
Output:

9. Incorrect statements about delegates are?
a) Delegates are reference types
b) Delegates are object oriented
c) Delegates are type safe
d) Only one method can be called using a delegate

Answer: d
Clarification: None.

10. Select the modifiers which control the accessibility of the delegate?
a) new
b) protected
c) public
d) all of the mentioned

Answer: d
Clarification: By definition

 

To practice basic questions and answers on all areas of C#, .

Leave a Reply

Your email address will not be published. Required fields are marked *