Which code should you use to replace line 05?

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 ‘inf. 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?

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 ‘inf. 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 = array1[0].Equals(typeof(int));

C.
var2 = Convert.ToInt32(array1[0]);

D.
var2 = ((int[])array1)[0];

Explanation:
Make a list of integers of the array with = ( (List<int>)arrayl) then select the first item in the list with
[0].



Leave a Reply 6

Your email address will not be published. Required fields are marked *


TheCoder

TheCoder

A is wrong, it gives and error

correct answer is C

Sampath

Sampath

A will gives following error.
“Cannot convert type ‘System.Collections.ArrayList’ to ‘System.Collections.Generic.List'”

So correct answer is C

Twórca C#

Twórca C#

C jak cebula – mój ulubiony owoc

SafeHub

SafeHub

Confirmed C has been tested and it is correct