I’m trying to use LINQ and I keep getting this error message:
Operator ‘<‘ cannot be applied to operands of type ‘Ilistprac.Location’ and ‘int’
I tried an override but I get an error message:
‘Ilistprac.Location.ToInt()’: no suitable method found to override
All the IList interfaces are implemented with the IEnurmerable too (just not listed here unless someone wants me to).
class IList2
{
static void Main(string[] args)
{
Locations test = new Locations();
Location loc = new Location();
test.Add2(5);
test.Add2(6);
test.Add2(1);
var lownumes = from n in test where (n < 2) select n;
}
}
public class Location
{
public Location()
{
}
private int _testnumber = 0;
public int testNumber
{
get { return _testnumber; }
set { _testnumber = value;}
}
public class Locations : IList<Location>
{
List<Location> _locs = new List<Location>();
public Locations() { }
public void Add2(int number)
{
Location loc2 = new Location();
loc2.testNumber = number;
_locs.Add(loc2);
}
}
You either want to compare
n.testNumberor you need to overload the<operator in theLocationclass so you can actually compare it to anint.