Не работает перегрузка true, false в LINQ
Есть класс Abonent, в котором я перегрузил true и false. Когда в классе Program я пишу следующее
Abonent[] arr = new Abonent[n];
// Тут заполняю массив
var arr1 = from p in arr
where p
select p;
То пишет, что не удается неявно преобразовать Abonent в bool. Но когда пишу
if(arr[0]){ }
то все работает. В чем может быть проблема?
Класс Abonent:
public class Abonent
{
public int Id { get; set; }
public string Sname { get; set; }
public string Name { get; set; }
public int Balance { get; set; }
public int Intern { get; set; }
public int Nintern { get; set; }
public static Abonent operator +(Abonent ab, int C)
{
Abonent ans = ab;
ans.Balance += C;
return ans;
}
public static bool operator true(Abonent ab1)
{
Abonent ab = ab1;
if (ab.Balance >= 10*ab.Intern + 5*ab.Nintern) return true;
return false;
}
public static bool operator false(Abonent ab1)
{
Abonent ab = ab1;
if (ab.Balance >= 10 * ab.Intern + 5 * ab.Nintern) return true;
return false;
}
public override string ToString()
{
return $"ID: {Id}, Name: {Name}, Surname: {Sname}, Balance: {Balance}, Intern: {Intern}, Not Intern: {Nintern}";
}
}