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

4/4

Page

Pick an option on a question to see the right 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(40);
        Console.WriteLine(g.pop());
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of the following is an incorrect statement about delegate?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which statement is valid for the following C# code snippet?
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);
    }
}

Select an option to see the answer and solution.

Which of the following are the correct statements about delegates?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Choose the incorrect statement among the following about the delegate?

Select an option to see the answer and solution.