当前位置: 首页>>代码示例>>C#>>正文


C# Customer.Where方法代码示例

本文整理汇总了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;
        }
开发者ID:andygco,项目名称:coursera-optimization-002-csharp,代码行数:34,代码来源:ExampleSolver.cs

示例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>());
 }
开发者ID:pstosio,项目名称:TP,代码行数:16,代码来源:LinqExtensions.cs


注:本文中的Customer.Where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。