本文整理汇总了C#中Customer.Where方法的典型用法代码示例。如果您正苦于以下问题:C# Customer.Where方法的具体用法?C# Customer.Where怎么用?C# Customer.Where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Customer
的用法示例。
在下文中一共展示了Customer.Where方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Solve
public SolutionResult Solve(Customer[] customers, int capacity, int numberOfVehicles)
{
var result = new SolutionResult(customers, numberOfVehicles);
customers[0].Covered = true;
var uncovered = customers.Where(i => !i.Covered).ToArray();
var vehicles = result.Vehicles;
var currentVehicleIndex = 0;
while (uncovered.Any())
{
var currentVehicle = vehicles[currentVehicleIndex];
var currentVehicle1 = currentVehicle;
var nextCustomers = uncovered.Where(i => i.Demand <= currentVehicle1.RemainingCapacity);
if (!nextCustomers.Any())
{
// we abandon our current vehicle and go to the next one
currentVehicleIndex++;
currentVehicle = vehicles[currentVehicleIndex];
}
var lastCustomer = currentVehicle.Path.Last();
nextCustomers = uncovered
.Where(i => i.Demand <= currentVehicle.RemainingCapacity)
.OrderBy(i => Vehicle.Distances[lastCustomer.Index, i.Index]);
currentVehicle.AddCustomer(nextCustomers.First());
uncovered = customers.Where(c => !c.Covered).ToArray();
}
return result;
}
示例2: FromClauseExample3
/// <summary>
/// Example #2: how to use an anonymous type in the select clause
/// </summary>
/// <returns>System.String.</returns>
public string FromClauseExample3()
{
Customer[] customers = new Customer[] { new Customer() { City = "Phoenix", Name = "Name1", Revenue=11.0E3F },
new Customer() { City = "NewYork", Name = "Name2", Revenue=12.0E4F },
new Customer() { City = "Phoenix", Name = "Name3", Revenue=13.0E4F },
new Customer() { City = "Washington", Name = "Name4", Revenue=14.0E4F }
};
// Example #2: var is required because the select clause specifies an anonymous type
//The compiler infers the types if not explicit stated.
var custQuery = customers.Where(cust => cust.City == "Phoenix").Select( cust=> new { cust.Name, cust.Revenue } );
return String.Join(";", custQuery.Select(x => String.Format("{0}:{1:F}", x.Name, x.Revenue)).ToArray<string>());
}