C# Collection Custom Order Display
Collection filter = new Collection();
//filter=Coming from External Source with different order Date is: S,O,M,C,I,R
//Now i have to change the order of filter based on some custom condition.
//I am going to take new collection with name:afterfilColl
Collection afterfilColl = new Collection();
if (filter.Items.Count != 0)
{
int countno = 8;
if (filter.Items.Count > 8)
{
countno = filter.Items.Count;
}
for (int i = 0; i < countno; i++)
{
afterfilColl.Insert(i, null);
}
}
int j = 0;
for (int i = 0; i < filter.Items.Count; i++)
{
if (filter.Items[i].Name == "M")
{
afterfilColl.RemoveAt(0);
afterfilColl.Insert(0, filter.Items[i]);
}
else if (filter.Items[i].Name == "I")
{
afterfilColl.RemoveAt(1);
afterfilColl.Insert(1, filter.Items[i]);
}
else if (filter.Items[i].Name == "C")
{
afterfilColl.RemoveAt(2);
afterfilColl.Insert(2, filter.Items[i]);
}
else if (filter.Items[i].Name == "R")
{
afterfilColl.RemoveAt(3);
afterfilColl.Insert(3, filter.Items[i]);
}
else if (filter.Items[i].Name == "O")
{
afterfilColl.RemoveAt(5);
afterfilColl.Insert(5, filter.Items[i]);
}
else if (filter.Items[i].Name == "S")
{
afterfilColl.RemoveAt(7);
afterfilColl.Insert(7, filter.Items[i]);
}
else
{
afterfilColl.Insert(j + 8, filter.Items[i]);
j++;
}
}
filter.Items.Clear();
for (int i = 0; i < afterfilColl.Count; i++)
{
if (afterfilColl[i] != null)
{
filter.Items.Add(afterfilColl[i]);
}
}
//Now i will get date in to filter collection with order of M,I,C,R,O,S
Collection filter = new Collection();
//filter=Coming from External Source with different order Date is: S,O,M,C,I,R
//Now i have to change the order of filter based on some custom condition.
//I am going to take new collection with name:afterfilColl
Collection afterfilColl = new Collection();
if (filter.Items.Count != 0)
{
int countno = 8;
if (filter.Items.Count > 8)
{
countno = filter.Items.Count;
}
for (int i = 0; i < countno; i++)
{
afterfilColl.Insert(i, null);
}
}
int j = 0;
for (int i = 0; i < filter.Items.Count; i++)
{
if (filter.Items[i].Name == "M")
{
afterfilColl.RemoveAt(0);
afterfilColl.Insert(0, filter.Items[i]);
}
else if (filter.Items[i].Name == "I")
{
afterfilColl.RemoveAt(1);
afterfilColl.Insert(1, filter.Items[i]);
}
else if (filter.Items[i].Name == "C")
{
afterfilColl.RemoveAt(2);
afterfilColl.Insert(2, filter.Items[i]);
}
else if (filter.Items[i].Name == "R")
{
afterfilColl.RemoveAt(3);
afterfilColl.Insert(3, filter.Items[i]);
}
else if (filter.Items[i].Name == "O")
{
afterfilColl.RemoveAt(5);
afterfilColl.Insert(5, filter.Items[i]);
}
else if (filter.Items[i].Name == "S")
{
afterfilColl.RemoveAt(7);
afterfilColl.Insert(7, filter.Items[i]);
}
else
{
afterfilColl.Insert(j + 8, filter.Items[i]);
j++;
}
}
filter.Items.Clear();
for (int i = 0; i < afterfilColl.Count; i++)
{
if (afterfilColl[i] != null)
{
filter.Items.Add(afterfilColl[i]);
}
}
//Now i will get date in to filter collection with order of M,I,C,R,O,S