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 11

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


Dominicana

Dominicana

Correct answer is C.

aaaa asasas

aaaa asasas

var2 = (int) array1[0];
var2 = array1.Cast().ToList()[0];
var2 = Convert.ToInt32(array1[0]);

Mr D

Mr D

The only answer that work here is C. var2 = Convert.ToInt32(array1[0]);

Mr D

Mr D

Or we can modify D with var2 = (int)array1[0];

sandip

sandip

C
or (int) array1[0];

Marina

Marina

(int)array1[0];
Convert.ToInt32(array1[0]);
array1.Cast<int>().ToList()[0];

answer: C

DAZANE

DAZANE

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
ArrayList array1 = new ArrayList();
int var1 = 10;
int var2;
array1.Add(var1);
var2 = Convert.ToInt32(array1[0]);

Console.WriteLine(“var1 = {0} and var2 = {1}”
,var1
,var2);
Console.ReadLine();
}
}
}

MB

MB

C

I would like to know who prepared answer…. paranoia

Béni

Béni

Other comments are right; the actual answer (A) gives a “Cannot convert type ‘System.Collections.ArrayList’ to ‘System.Collections.Generic.List’.
Only good answer is C, that compiles perfectly fine.