I am trying to create a function that compares the values inside an array.
(In this case I just an example for an integer). The contents of the array are user inputs. Whenever the function encounters a value that is the same with other values inside the array it should overwrite the other values that are not equal to him.
In my example the result of the array should be {1,1,1} because it encounters a same value '1'. There will always be 3 values inside the array.
Expand|Select|Wrap|Line Numbers
- int[] inputs = { 1, 2, 1 };
- int holder = 0;
- bool equalresult = false;
- for (int objctr = 0; objctr < inputs.Length; objctr++)
- {
- holder = inputs[objctr];
- for (int inobjctr = objctr + 1; inobjctr < inputs.Length; inobjctr++)
- {
- equalresult = int.Equals(inputs[objctr],inputs[inobjctr]);
- if (equalresult)
- {
- holder = inputs[inobjctr];
- }
- }
- }
thanks a lot in advance.