0
votes

Writing a comparer, the numbers can be from 1-20.

I have 2 hashtables that contain numbers:

htGroup1

htGroup2

The hashtables cover all the numbers between 1 and 20.

Now I'm writing a custom comparer for some commercial grid control, and it provides me with Value1 and Value2.

I have to set a property with either 0 (match), -1 or 1:

e.Result = result; // where result is 0, 1 or -1.

How can I determine the result so it groups all numbers into 2 sets (based on Group1 and Group2).

I'm writing a custom comparer for a devexpress aspxgrid control, details here: http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_CustomColumnGrouptopic

1

1 Answers

1
votes

Return 0 if they are in the same group, 1/-1 otherwise (does not really matter if you have just 2 groups.

int ComareResult(int a, int b)
{
   var groupA = a <=20 && a >=1;
   var groupB = b <=20 && b >=1;
   return groupA == groupB ? 0 : a <b ? -1 : 1;
}