C # - Generics Question and Answer

C # - Generics Question and Answer
11. For the code snippet given below, which of the following statements are valid?

public class MyContainer<T> where T: class, IComparable
{
    //Insert code here
}

    Class MyContainer requires that it's type argument must implement IComparable interface.
    Compiler will report an error for this block of code.
    There are multiple constraints on type argument to MyContainer class.
    Class MyContainer requires that its type argument must be a reference type and it must implement IComparable interface.
  • 1 and 2 Only
  • 3 and 4 Only
  • 2 and 3 Only
  • All of the above
Show Answer
12. Which of the following statements is valid about advantages of generics?
  • Generics shift the burden of type safety to the programmer rather than compiler.
  • Generics require use of explicit type casting.
  • Generics provide type safety without the overhead of multiple implementations.
  • Generics eliminate the possibility of run-time errors.
Show Answer
Questions and Answers for Competitive Exams Various Entrance Test