elandh ricky
elandh ricky

Reputation: 41

Array[] - Can't get the value in Array[] C# "cannot implicitly convert type object to int"

example :

Array[] hasil = new Array[1];
hasil[0] = new int[1];
hasil[0].SetValue(99, 0);
int xx = hasil[0].GetValue(0);

why I can't get hasil[0].GetValue(0) it say "cannot implicitly convert type object to int"

Upvotes: 0

Views: 1302

Answers (2)

Pawan Nogariya
Pawan Nogariya

Reputation: 8980

GetValue method returns object type so you have to explicitly convert it to int

Like this

int xx = (int)hasil[0].GetValue(0);

Upvotes: 2

romain-aga
romain-aga

Reputation: 1561

Cast your value:

(int)hasil[0].GetValue(0);

When your compilator says it can't implicitly cast, you have to do it explicitly. Then add a cast.

Upvotes: 0

Related Questions