0

How one use the value an array in another method?

//consider this please, int sum =0; int[] scores = new int[10]; for (int i = 0; i < 10; i++) { scores [I] = int.Parse(Console.Readline()); sum +=I; } I want to use the values in 'scores[]' in another method to calculate the percentage using individual values keyed in. help!

29th Jul 2016, 1:43 PM
Markanthony
Markanthony - avatar
3 Answers
+ 1
Make a method that accepts int[] as a parameter so you pass in your scores array. Then do your calculation in that method to get the percentage.
29th Jul 2016, 1:58 PM
John-Michael Merino Trembath
John-Michael Merino Trembath - avatar
+ 1
Anytime you'd like to use certain values in an array, use the index of that value. arrayName[5] this gets the sixth value in the array that starts at index 0. You can also use a contains method if you don't know the index but you know the value. When you want to use all the values in the array, use a loop with an incrementing value to use as an index. arrayName[i].
29th Jul 2016, 11:58 PM
nk361
nk361 - avatar
0
if the method is within the same class, declare the array as a property of the class and any method can use it.
2nd Aug 2016, 8:14 PM
Stephen Coyle
Stephen Coyle - avatar