Generics Questions and Answers

Take Exam

Generics in C# programming questions with answers test your knowledge of type safety, reusability, and performance in modern C# development. Understanding generics is crucial for building flexible and maintainable code, especially for technical interviews and placement tests at companies like Capgemini, Accenture, and Cognizant. These programming questions and answers cover key topics like generic classes, methods, constraints, and collections. Practicing these MCQs enhances your ability to write type-safe and efficient code, a skill highly valued in software engineering roles. Try solving C# generics MCQs online or download C# programming practice PDFs for self-assessment.

Generics

Showing 10 of 32 questions

21. What is type erasure in context of C# generics?

  • C# removes type information at runtime
  • C# maintains type information at runtime
  • Type information is stored in metadata only
  • Types are converted to object references
Show Answer Report

22. Which collection is generic in C#?

  • ArrayList
  • Hashtable
  • List<T>
  • Queue
Show Answer Report

23. What does covariance allow in generics?

  • Using less derived types
  • Using more derived types
  • Using any type
  • Using only value types
Show Answer Report

24. Which interface supports covariance in C#?

  • IList<T>
  • ICollection<T>
  • IEnumerable<T>
  • IDictionary<T>
Show Answer Report

25. What is the purpose of the "in" keyword in generic interfaces?

  • Makes parameter covariant
  • Makes parameter contravariant
  • Restricts to input parameters
  • Allows output parameters only
Show Answer Report

26. Which constraint would you use for value types?

  • where T : class
  • where T : struct
  • where T : value
  • where T : valuetype
Show Answer Report

27. What happens if you don't specify constraints on a generic type?

  • All operations are available
  • Only System.Object operations are available
  • The type cannot be used
  • Runtime type checking is enforced
Show Answer Report

28. How do you create a generic method?

  • void Method<T> { }
  • void Method(T param) { }
  • void <T>Method() { }
  • void Method()<T> { }
Show Answer Report

29. Which of these is a benefit of generics?

  • Reduced code readability
  • Eliminates boxing and unboxing
  • Increased memory usage
  • Dynamic type checking
Show Answer Report

30. What does the "out" keyword do in generic interfaces?

  • Makes parameter input-only
  • Makes parameter output-only
  • Makes parameter covariant
  • Makes parameter contravariant
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test