I still do not get it to the person who marked my question as duplicate. Does the question linked mean I can't, or I can? If it means I can then how? Do I need to redefine ICompareable? Do I need to customize my own method of comparison to compare elements of 2 List?
Original question below
I'm playing with generics in C#. I have 2 lists of type T. Doing a "Less than or Equal to" comparison is apparently a no no. So is there a way I can correctly compare elements between 2 generic lists?
This is for the purpose of learning for fun so no particular task/end goal.
class aClass<T>
{
public void Compare_Generics(T[] m)
{
var result = new List<T>();
var left = new List<T>();
var right = new List<T>();
for(int i = 0; i < m.Length; i++)
{
if(i < m.Length/2)
left.Add(m[i];
else
right.Add(m[i]);
}
if(left[0] <= right[0])//This is the no no line that the compiler does not like
{
result.Add(left[0]);
}
}
}