exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 2 question 159 discussion

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

You are developing an application.
The application contains the following code segment (Line numbers are included for reference only):

When you run the code, you receive the following error message: "Cannot implicitly convert type 'object'' to 'int'. An explicit conversion exists (are you missing a cast?)."
You need to ensure that the code can be compiled.
Which code should you use to replace line 05?

  • A. var2 = ((List<int>)array1) [0];
  • B. var2 = (int) array1[0];
  • C. var2 = int.Parse(array1[0]);
  • D. var2 = array1[0] as int;
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

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
hsjo
Highly Voted 4 years, 7 months ago
answer is b Tested
upvoted 5 times
...
Rarabel
Most Recent 4 years, 5 months ago
A.Will not convert System.Collections.ArrayList to System.Collections.Generic.List<T>. B.Correct C. elements of the ArrayList are not strings. D. As operator can be applied only to reference or nullable types.
upvoted 1 times
...
josuke
5 years, 1 month ago
Why is D considered invalid? Is it because the conversion would attempt to assign null to var2 if the cast failed? I'm not sure how that would be any worse than throwing an exception in the first place if the standard cast fails.
upvoted 1 times
soats
4 years, 11 months ago
It's because you cannot use AS on non-nullable types
upvoted 3 times
...
...
BitMan20
5 years, 5 months ago
why not c?
upvoted 1 times
osaki
5 years, 5 months ago
cause array1[0] is not a string
upvoted 8 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 ...