You have a class named Customer and a variable named customers. You need to test whether the customers variable is a generic list of Customer objects. Which line of code should you use?
Suggested Answer:D🗳️
If you want to check if it's an instance of a generic type: return list.GetType().IsGenericType; If you want to check if it's a generic List<T>: return list.GetType().GetGenericTypeDefinition() == typeof(List<>); Reference: Testing if object is of generic type in C# http://stackoverflow.com/questions/982487/testing-if-object-is-of-generic-type-in-c-sharp
A is correct.
Option D will compile, but will not do what is intended. Additionally, the compiler will issue this: warning CS0184: The given expression is never of the provided ('List<Customer>') type
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Xavios
Highly Voted 5 years, 7 months agoMitsoshima
Highly Voted 5 years, 5 months agonoussa
Most Recent 3 years, 11 months agomohmou
4 years, 4 months agowhtvr
4 years, 9 months agosscooter1010
4 years, 10 months agodakuan
5 years, 1 month ago