This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Choose the best response for each of the following questions.
What is the primary purpose of generics in programming?
To allow code to handle multiple data types while ensuring type safety.
To improve runtime performance by optimizing memory usage.
To simplify debugging by automatically generating error messages.
Which of the following is an example of a generic class?
public class Box<T> { public T Item { get; set; } }
public class Box { public int Item { get; set; } }
public class Box { public void AddItem(string item) { } }
Which of the following scenarios is a common use case for anonymous types in C#?
Projecting selected properties in a Language-Integrated Query (LINQ).
Defining a reusable class for multiple methods.
Creating mutable objects for data manipulation.
You must answer all questions before checking your work.
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?