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

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 = arrayl[0] is int;

B.
var2 = ( (List<int>)arrayl) [0];

C.
var2 = arrayl[0].Equals(typeof(int));

D.
var2 = (int) arrayl [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 9

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


Dhruv

Dhruv

Correct answer is D. I have confirmed it by writing a snippet.

Use the following snippet to verify.

ArrayList array1 = new ArrayList();
int var1 = 10;
int var2;
array1.Add(var1);
//var2 = array1[0]; //Throws an error
var2 = (int)array1[0];
Console.WriteLine(“Value of var2 = {0}”, var2);
var2 = Convert.ToInt32(array1[0]);
Console.WriteLine(“Value of var2 = {0}”, var2);

devprof

devprof

I confirm the correct answer is D

Mr D

Mr D

D is the right answer

Saikat

Saikat

D is write answer. Dear Poster, please don’t post wrong answers.

Saikat

Saikat

D is right* answer. Dear Poster, please don’t post wrong answer(s).

Sheva

Sheva

of cource D

Raghu

Raghu

Correct answer is D.Is there a way to modify the answers in