0

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"

2
  • Is there a good reason why you're using an Array[] filled with int[] instead of using directly an int[][]? Commented May 29, 2016 at 11:29
  • because sometimes the data not always int[] and n params Commented May 31, 2016 at 8:41

2 Answers 2

2

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

Like this

int xx = (int)hasil[0].GetValue(0);
Sign up to request clarification or add additional context in comments.

2 Comments

Extra info: In the Array class you can find: 'public object GetValue(int index);' So as Pawan noted, the return type of the GetValue method is object.
Welcome! If it works for you, please mark the answer correct by clicking on the check mark.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.