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 2 of 7

Q11.
Suppose on pushing a button an object is to be notified, but it is not known until runtime which object should be notified. Which of the following programming constructs should be used to implement this idea?
Discuss
Answer: (b).Delegate
Discuss
Answer: (c).Delegate is a value type.
Q13.
Suppose a Generic class called SortObjects is to be made capable of sorting objects of any type (Integer, Single, Byte etc.). Which of the following programming constructs should be used to implement the comparision function?
Discuss
Answer: (d).Delegate
Q14.
With which of the following can the ref keyword be used?

1. Static data
2. Instance data
3. Static function/subroutine
4. Instance function/subroutine
 
Discuss
Answer: (b).3, 4
Q15.
Which one of the following classes are present System.Collections.Generic namespace?

1. Stack
2. Tree
3. SortedDictionary
4. SortedArray
Discuss
Answer: (c).1 and 3 only
Q16.
For the code snippet shown below, which of the following statements are valid?

public class Generic<T>
{
    public T Field; 
    public void TestSub()
    {
        T i = Field + 1;
    }
}
class MyProgram
{
    static void Main(string[] args)
    {
        Generic<int> gen = new Generic<int>();
        gen.TestSub();
    }
}
Discuss
Answer: (d).Compiler will report an error: Operator '+' is not defined for types T and int.
Q17.
Which of the following statements are valid about generics in .NET Framework?

1. Generics is a language feature.
2. We can create a generic class, however, we cannot create a generic interface in C#.NET.
3. Generics delegates are not allowed in C#.NET.
4. Generics are useful in collection classes in .NET framework.
5. None of the above
Discuss
Answer: (c).1 and 4 Only
Discuss
Answer: (d).Generic procedures must take at least one type parameter.
Q19.
For the code snippet shown below, which of the following statements are valid?

public class TestCompSciBits
{
    public void TestSub<M> (M arg)
    {
        Console.Write(arg);
    }
}
class MyProgram
{
    static void Main(string[] args)
    {
        TestCompSciBits Bits = new TestCompSciBits();
        Bits.TestSub("CompSciBits ");
        Bits.TestSub(4.2f);
    }
}
Discuss
Answer: (a).Program will compile and on execution will print: CompSciBits 4.2
Q20.
For the code snippet given below, which of the following statements is valid?

public class Generic<T>
{
    public T Field;
}
class Program
{
    static void Main(string[ ] args)
    {
        Generic<String> g = new Generic<String>();
        g.Field = "Hello";
        Console.WriteLine(g.Field);
    }
}
Discuss
Answer: (a).It will print string "Hello" on the console.
Page 2 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!