It's not entirely clear what you are asking, so I will try to explain some basic concepts.
First of all, since you have a List<Turbines>
and List<T>
implements IEnumerable<T>
, you can use the .Where
extension method.
This method acts on an IEnumerable<TSource>
, and takes as argument a predicate with the signature Func<TSource, bool>
. You can pass this argument in several ways, the two more common being 1) with a lambda and 2) with a classic method:
public class YourClass
{
public void YourMethod()
{
List<Turbines> newTur = new List<Turbines>
{
new Turbines { Turname = "inUK", TurID = 1245, Production = 1452.22, Availability = 52.12 },
new Turbines { Turname = "InUS", TurID = 125, Production = 1052.22, Availability = 92.12 }
};
// 1) passing filter as a lambda
IEnumerable<Turbines> filteredListWithLambda = newTur.Where(t => t.Availability > 90.0 && t.Production > 1300);
// 2) passing filter as a method
IEnumerable<Turbines> filteredListWithMethod = newTur.Where(Filter);
}
private bool Filter(Turbines turbines)
{
return turbines.Availability > 90.0 && turbines.Production > 1300;
}
}
If you want to change the values of your filter, you will have have to receive in YourMethod
these values, and plug them in the filter, like this:
public class YourClass
{
public void YourMethod(double availability, int production)
{
List<Turbines> newTur = new List<Turbines>
{
new Turbines { Turname = "inUK", TurID = 1245, Production = 1452.22, Availability = 52.12 },
new Turbines { Turname = "InUS", TurID = 125, Production = 1052.22, Availability = 92.12 }
};
IEnumerable<Turbines> filteredListWithLambda = newTur.Where(t => t.Availability > availability && t.Production > production);
}
}
Where(...)
clause, other than that it's not clear what you are really asking here.