this is a more elegant solution:
try this and let me know if it works.
public class MyComparer2 : IComparer
{
private SortedList mSortedList;
public SortedList SortedList
{
get{return mSortedList;}
set{mSortedList = value;}
}
int IComparer.Compare(Object x, Object y)
{
int keyLeft = (int) x;
int keyRight = (int) y;
return((new CaseInsensitiveComparer()).Compare(mSortedList[y],
mSortedList[x]));
}
}
public void test()
{
MyComparer2 comparer = new MyComparer2();
SortedList sortedList = new SortedList(comparer);
comparer.SortedList = sortedList;
sortedList.Add(1,3);
sortedList.Add(2,4);
sortedList.Add(3,2);
sortedList.Add(4,5);
sortedList.Add(5,1);
//Here we look for keys....
Console.WriteLine(sortedList[3]); // the return object is "2";
//The SortedList was dinamically sorted by the second column when the
items are loaded.
foreach(int i in sortedList.Keys)
Console.WriteLine("Index:" + sortedList.IndexOfKey(i) + " Key:" + i + "
Value:" + sortedList
);
//It should shows
//Index:1 Key: 5 Value: 1
//Index:2 Key: 3 Value: 2
//Index:3 Key: 1 Value: 3
//Index:4 Key: 2 Value: 4
//Index:5 Key: 4 Value: 5
}
Gustavo
Franco said:
SqlParameterCollection[] myParams=new SqlParameterCollection[3];
A fixed array doesn't have a .Add method because it is "fixed".
You can do:
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10);
par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value;
replace
myParams.Add(par1); - - there is no ADD method ?
by
myParams
= par1; // where i is from the index (0 to 2 ) of yours
fixed array.
The best solution.
Replace:
SqlParameterCollection[] myParams=new SqlParameterCollection[3];
by
SqlParameterCollection myParams=new ArrayList();
then you can use
myParams.Add(par1); - now there is ADD method!!!
Gustavo.
Brian Delahunty said:
So you want an array of collections? Any particular reason why?
SqlParamaterCollection does not have a publically available constructor
so
am I correct in assuming that this is why you are using an array of the
collections?
:
I'm going from VB to C#.
I have example in VB:
Dim myParams As New Collection
Dim par 1 as SqlParameter
par1 = New SqlParameter("@mediaId", SqlDbType.NVarChar, 10)
par1.Value = lstMedia.Items(lstMedia.SelectedIndex).Value
myParams.Add(par1)
I would like to do the similar in C#:
SqlParameterCollection[] myParams=new SqlParameterCollection[3];
SqlParameter par1;
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10);
par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value;
myParams.Add(par1); - - there is no ADD method ?
Any solution?
Regards,Simon