Trying to compare 2 int arrays.
Example:
public static void Main()
{
int[] T1 = new int[3] { 1, 2, 3 };
int[] D1 = new int[3] { 4, 5, 6 };
Would like to compare value T1 index[0...3] to D1 index[0...3].
There are 3 possibilities I am interested in and capturing.
1. are they equal
2 & 3. is one < or > then the other.
Any help on structuring a compare or equals statement would be appreciated.
Loading

Danatas GerviRank #4,152 · 361 reputationPosted Jul 28, 2009, 10:52 PM EDT
May be array of results?
H Ghasemi8 reputationPosted Jul 29, 2009, 7:04 AM EDT
Danatas GerviRank #4,152 · 361 reputationPosted Jul 29, 2009, 7:54 AM EDT
But what do you mean as "array index"?
Sum of all elements? Lenght of array? Index - this is number of element in array!
Your task is not usial - seems you want to compare only first element of boths arrays....
so it may be shorter to write :
public int CompareArray(int[] t, int[] d) { if (t.Length > 0) { if (d.Length > 0) { return Math.Sign( t[0]- d[0]); } } return 0; }Lets continue to develope the algoritm of comparing:
take t - array of int and d - array of int.
if t[0] > d[0] -> true or false
if t[1] > d[0] -> true or false
if t[2] > d[0] -> true or false
if t[0] > d[1] -> true or false
if t[1] > d[1] -> true or false
if t[2] > d[1] -> true or false
if t[0] > d[2] -> true or false
if t[1] > d[2] -> true or false
if t[2] > d[2] -> true or false
how do you want to collect the resut?
H Ghasemi8 reputationPosted Jul 30, 2009, 8:59 PM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Jul 30, 2009, 9:11 PM EDT