You could try to implement a custom
IComparer<int>:
.
public VerySpecialInt32Comparer : IComparer<int>
{
public int Compare(int left, int right) {
int result;
if (left == right) {
result = 0;
}
if (left == 3) {
result = 1;
}
else if ((left == 5) && (right != 3)) {
result = 1;
}
else if ((left == 2) && ((right != 3) && (right != 5)) {
result = 1;
}
else if ((left == 4) && ((right != 3) && (right != 5) && (right != 2)) {
result = 1;
}
else {
result = -1;
}
return result;
}
}
Once you defined the
IComparer<T>
implementation, you will have to use it on a
List<int>
. Transform your
IEnumerable<int>
into a
List<int>
this way:
using System.Linq;
IList<int> list = iEnumVariable.ToList();
Finally use the specific comparer implementation:
list.Sort(new VerySpecialInt32Comparer());
Warning! I took into account that there are only 5 values possible (2, 3, 4, 5 and 6). If there are more of them, this alogorithm will not work; you will have to adapt it to your needs.
Hope this helps. Good luck.