Ad

Ad

  • NA
  • 9
  • 0

each array element as an individual number?

Sep 10 2004 7:25 AM
Hi, I have a simple array like this: public static int[] numbers = new int[] { 27, 13, 44, 5, }; I have just shortened it but it is a lot bigger. What I want to do is if a number is picked and it exists in the array of numbers by doing something like this: foreach ( int equal in kills ) { if ( chosen == equal ) { } } What I am having trouble is, if the number picked is, for example 5, as it's the 4th element, add the number 3 to a different var. Again, if the number picked is 27 then add nothing. Is this something that can be done? Would I be right to do something like numbers[4] = 4? Would that overwrite what 5 is and make it 4? Thanks for any help