adplus-dvertising

Welcome to the Delegates and Generics MCQs Page

Dive deep into the fascinating world of Delegates and Generics with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Delegates and Generics, a crucial aspect of C# Programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Delegates and Generics, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within C# Programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Delegates and Generics. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of C# Programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Delegates and Generics. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Delegates and Generics MCQs | Page 6 of 7

Explore more Topics under C# Programming

Discuss
Answer: (b).public name { /* โ€ฆ */ }
Q52.
Which of these type parameters is used for generic methods to return and accept any type of object?

a.

K

b.

N

c.

T

d.

V

Discuss
Answer: (c).T
Q53.
What will be the output of the given code snippet?
class a
{
    public void x(int p, double k)
    {
        Console.WriteLine("k : csharp!");
    }
}public class Generic<T>
{
    Stack<T> stk = new Stack<T>();
    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<string> g = new Generic<string>();
        g.push(40);
        Console.WriteLine(g.pop());
        Console.ReadLine();
    }
}
Discuss
Answer: (c).40
Q54.
What will be the output of the given code snippet?
public class Generic<T>
{
    Stack<T> stk = new Stack<T>();
    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<int> g = new Generic<int>();
        g.push("Csharp");
        Console.WriteLine(g.pop());
        Console.ReadLine();
    }
}
Discuss
Answer: (b).Csharp
Q55.
For the code set given below,which of the following statements are perfectly valid?
public class MyContainer<T> where T: class, IComparable
{
  /* insert code here */
}
Discuss
Answer: (b).There are multiple constraints on type argument to MyConatiner class
Q56.
For the code given below which statements are perfectly valid?
public class Csharp
{
    public void subject<S>(S arg)
    {
        Console.WriteLine(arg);
    }
}
class Program
{
    static Void Main(string[] args)
    {
        Csharp c = new Csharp();
        c.subject("hi");
        c.subject(20);
    }
}
Discuss
Answer: (c).Code runs successfully and prints required output
Discuss
Answer: (a).generics are useful in collection classes in .NET framework
Q58.
Which statement is valid for the given snippet of code:
public class Generic<T>
{
    public T Field;
}
class Program
{
    static void Main(string[] args)
    {
        Generic<String> g = new Generic<String>();
        g.Field = "Hi";
        Console.WriteLine(g.Field);
    }
}
Discuss
Answer: (d).Code runs successfully
Q59.
Which statement is valid for the given snippet of code:
public class Generic<T>
 {
     public T Field;
 }
 class Program
 {
     static void Main(string[] args)
     {
         Generic<int> g2 = new Generic<int>();
         Generic<int> g3 = new Generic<int>();
         g2.Field = 8;
         g3.Field = 4;
         if (g2.Field % g3.Field == 0)
         {
             Console.WriteLine("A");
         }
         else
         Console.WriteLine("Prints nothing:");
         Console.ReadLine();
     }
 }
Discuss
Answer: (b).A
Discuss
Answer: (b).Generic procedures should take at least one type parameter
Page 6 of 7

Suggested Topics

Are you eager to expand your knowledge beyond C# Programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!