Computer

Delegates And Events In C Sharp MCQs

Practice Delegates And Events In C Sharp MCQs for competitive exams.

Delegates And Events In C Sharp MCQs

Practice questions from this topic.

Choose the incorrect statement among the following about the delegate?

  1. A. delegates are of reference types
  2. B. delegates are object oriented
  3. C. delegates are type safe
  4. D. none of the mentioned
Report Error

Which among the given classes is present in System.Collection.Generic.namespace?

  1. A. Stack
  2. B. Tree
  3. C. Sorted Array
  4. D. All of the mentioned
Report Error

Which among the given classes represents System.Collections.Generic namespace?

  1. A. SortedDictionary
  2. B. Sorted Array
  3. C. Stack
  4. D. All of the mentioned
Report Error

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

  1. A. Test Your
  2. B. Test-Your-C#.NET-Skills
  3. C. ur C#.NET Skills
  4. D. None of the mentioned
Report Error

Which of the following are the correct statements about delegates?

  1. A. Delegates can be used to implement callback notification
  2. B. Delegates permit execution of a method on a secondary thread in an asynchronous manner
  3. C. Delegate is a user defined type
  4. D. All of the mentioned
Report Error

Which statement is valid for the following C# code snippet? public class Generic { public T Field; } class Program { static void Main(string[] args) { Generic g = new Generic(); g.Field = "Hi"; Console.WriteLine(g.Field); } }

  1. A. Compile time error
  2. B. Generic being a keyword cannot be used as a class name
  3. C. Runtime error
  4. D. Code runs successfully
Report Error

What will be the output of the following C# code? public class Generic { public T Field; } class Program { static void Main(string[] args) { Generic g2 = new Generic(); Generic g3 = new Generic(); g2.Field = 8; g3.Field = 4; if (g2.Field % g3.Field == 0) { Console.WriteLine("A"); } else Console.WriteLine("Prints nothing:"); Console.ReadLine(); } }

  1. A. Compile time error
  2. B. A
  3. C. Run time error
  4. D. Code runs successfully but prints nothing
Report Error

Suppose a Generic class called as SortObjects is to be made capable of sorting objects of any type(integer, single, byte etc). Then, which of the following programming constructs is able to implement the comparison function?

  1. A. interface
  2. B. encapsulation
  3. C. delegate
  4. D. attribute
Report Error

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

  1. A. delegate void del(int a); csharp s = new csharp(); del d = new del(ref s.abc); d(10)
  2. B. csharp s = new csharp(); delegate void d = new del(ref abc); d(10)
  3. C. delegate int del(int a); del d; csharp s = new csharp(); d = new del(ref s.fun); d(10)
  4. D. none of the mentioned
Report Error

Which of the following is an incorrect statement about delegate?

  1. A. a single delegate can invoke more than one method
  2. B. delegates could be shared
  3. C. delegates are type safe wrappers for function pointers
  4. D. delegate is a value type
Report Error

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

  1. A. Delegates in C#.NET is a base class for all delegates type
  2. B. Delegates created in C#.NET are further not allowed to derive from the delegate types that are created
  3. C. Only system and compilers can derive explicitly from the Delegate or MulticasteDelegate class
  4. D. All of the mentioned
Report Error

What will be the output of the following C# code snippet? public class Generic { Stack stk = new Stack(); public void push(T obj) { stk.Push(obj); } public T pop() { T obj = stk.Pop(); return obj; } } class Program { static void Main(string[] args) { Generic g = new Generic(); g.push(40); Console.WriteLine(g.pop()); Console.ReadLine(); } }

  1. A. 0
  2. B. Runtime Error
  3. C. 40
  4. D. Compile time Error
Report Error