exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 2 question 131 discussion

Actual exam question from Microsoft's 70-483
Question #: 131
Topic #: 2
[All 70-483 Questions]

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?

  • A. Option A
  • B. Option B
  • C. Option C
  • D. Option D
Show Suggested Answer Hide Answer
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

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Xavios
Highly Voted 5 years, 7 months ago
Should be A
upvoted 30 times
...
Mitsoshima
Highly Voted 5 years, 5 months ago
Got it tested...it's A
upvoted 20 times
...
noussa
Most Recent 3 years, 11 months ago
The correct answer is A
upvoted 2 times
...
mohmou
4 years, 4 months ago
A: Tested
upvoted 5 times
...
whtvr
4 years, 9 months ago
With D the actual type returned by the GetType() would be "System.Type", so no way it would work
upvoted 4 times
...
sscooter1010
4 years, 10 months ago
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
upvoted 5 times
...
dakuan
5 years, 1 month ago
A is correct.
upvoted 7 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
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.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago