My Report

C# Generic Test – 1


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. Choose the advantages of using generics?

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

3. Select the type argument of an open constructed type?

4. What is meant by the term generics?

5. Which of these type parameters is used for generic methods to return and accept any type of object?

6. What does the following C# code block defines?

 class Gen<T> 
 {  
      T ob;    
 }

7. What will be the output of the following C# 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<string> g = new Generic<string>();
        g.push(40);
        Console.WriteLine(g.pop());
        Console.ReadLine();
    }
}

8. What does the following C# code set defines?

 public Gen(T o) 
 {
      ob = o; 
 }

9. What will be the output of the following C# 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();
    }
}

10. Are generics in C# are same as the generics in java and templates in C++?

11. Which of these is a correct way of defining generic method?

12. 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!");
    }
}

 

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.