What you want to do is use a Hashtable to store a key value.
I didnt test it.
But I don't see why it shouldn't work.
public struct KeyValue
{
public KeyValue(int key, int value)
{
Key = key;
Value = value;
}
public int Key;
public int Value;
}
public class MyComparer : IComparer
{
int IComparer.Compa re(Object x, Object y)
{
KeyValue keyValueLeft = (KeyValue) x;
KeyValue keyValueRight = (KeyValue) y;
return((new CaseInsensitive Comparer()).Com pare(keyValueRi ght.Value,
keyValueLeft.Va lue));
}
}
public void test()
{
ArrayList array = new ArrayList();
array.Add(new KeyValue(1,3));
array.Add(new KeyValue(2,4));
array.Add(new KeyValue(3,2));
array.Add(new KeyValue(4,5));
array.Add(new KeyValue(5,1));
array.Sort(new MyComparer());
Hashtable table = new Hashtable();
foreach(KeyValu e keyValue in array)
table.Add(keyVa lue.Key, keyValue.Value) ;
//Here we look for keys....
Console.WriteLi ne(table[3]); // the return object is "2";
//The hastable was already loaded with sorted Key Values by the second
colum.
foreach(int i in table.Keys)
Console.WriteLi ne("Key:" + i + " Value:" + table[i]);
//It should shows
//Key: 5 Value: 1
//Key: 3 Value: 2
//Key: 1 Value: 3
//Key: 2 Value: 4
//Key: 4 Value: 5
}
Gustavo.
"Arjen" <bo*****@hotmai l.com> wrote in message
news:dc******** **@news4.zwoll1 .ov.home.nl...
Hi,
I need to add this inside an array:
1 3
2 4
3 2
4 5
5 1
I think of using this:
Int32[,] myValues;
Now I want to find a value (index) in the first colomn. Let's say I'm
looking for value 3, the find result will be 3.
After that I want to sort the array bases on the values in column two.
How can I do that?
Thanks!