Vidyalelo
C# Programming · all questions

Delegates and Events in C Sharp
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

72

Questions

3/4

Page

Pick an option on a question to see the right answer and solution.

Choose the incorrect statement about delegates?

Select an option to see the answer and solution.

Incorrect statements about delegates are?

Select an option to see the answer and solution.

What does the following C# code block defines?
class Gen<T> 
{  
     T ob;    
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which among the following is the correct statement about delegate declaration?
delegate void del(int i);

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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(30);
        Console.WriteLine(g.pop());
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Which of the given statements are valid about generics in .NET Framework?

Select an option to see the answer and solution.

Which of the following statements are valid in the following C# code snippet?
public class Generic<T>
{
    public T Field;
    public void testSub()
    {
        T i = Field + 1;
    }
}
class Program
{
    static void Main(string[] args)
    {
        Genericlt;int>g = new Genericlt;int>();
        g.testSub();
    }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

In the following C# code, which of the following statements are perfectly valid?
public class MyContainer<T> where T: IComparable
{
  /* insert code here */
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

In the following C# code, 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);
    }
}

Select an option to see the answer and solution.

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("C++");
        Console.WriteLine(g.pop() + " ");
        Generic<int> g1 = new Generic<int>();
        g1.push(20);
        Console.WriteLine(g1.pop());
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Choose the advantages of using generics?

Select an option to see the answer and solution.