本文整理汇总了C#中Common.List.First方法的典型用法代码示例。如果您正苦于以下问题:C# List.First方法的具体用法?C# List.First怎么用?C# List.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Common.List
的用法示例。
在下文中一共展示了List.First方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateOrder
public static OrderCalculationResponse CalculateOrder(OrderCalculationRequest request, bool hasAutoOrder = false)
{
var result = new OrderCalculationResponse();
if (request.Items.Count() == 0) return result;
if (request.Address == null) request.Address = GlobalSettings.Company.Address;
if (request.ShipMethodID == 0) request.ShipMethodID = request.Configuration.DefaultShipMethodID;
var apirequest = new CalculateOrderRequest();
apirequest.WarehouseID = request.Configuration.WarehouseID;
apirequest.CurrencyCode = request.Configuration.CurrencyCode;
apirequest.PriceType = request.Configuration.PriceTypeID;
apirequest.ShipMethodID = request.ShipMethodID;
apirequest.ReturnShipMethods = request.ReturnShipMethods;
apirequest.City = request.Address.City;
apirequest.State = request.Address.State;
apirequest.Zip = request.Address.Zip;
apirequest.Country = request.Address.Country;
apirequest.Details = request.Items.Select(c => new OrderDetailRequest(c)).ToArray();
if(hasAutoOrder){
apirequest.OrderType = Common.Api.ExigoWebService.OrderType.AutoOrder;
}
var apiresponse = Exigo.WebService().CalculateOrder(apirequest);
result.Subtotal = apiresponse.SubTotal;
result.Shipping = apiresponse.ShippingTotal;
result.Tax = apiresponse.TaxTotal;
result.Discount = apiresponse.DiscountTotal;
result.Total = apiresponse.Total;
// Assemble the ship methods
var shipMethods = new List<ShipMethod>();
if (apiresponse.ShipMethods != null && apiresponse.ShipMethods.Length > 0)
{
foreach (var shipMethod in apiresponse.ShipMethods)
{
shipMethods.Add((ShipMethod)shipMethod);
}
// Ensure that at least one ship method is selected
var shipMethodID = (request.ShipMethodID != 0) ? request.ShipMethodID : request.Configuration.DefaultShipMethodID;
if (shipMethods.Any(c => c.ShipMethodID == (int)shipMethodID))
{
shipMethods.First(c => c.ShipMethodID == shipMethodID).Selected = true;
}
else
{
shipMethods.First().Selected = true;
}
}
result.ShipMethods = shipMethods.AsEnumerable();
return result;
}
示例2: search
public double[] search()
{
List<Bee> bee = new List<Bee>();
Bee best = new Bee(argCnt);
List<Bee> workBee = new List<Bee>();
List<Bee> newWorkBee = new List<Bee>();
Bee tmp;
//Step 2
for (int i = 0; i < B; i++)
{
tmp = getRandBee();
bee.Add(tmp);
}
iter = 1;
//Step 3
best.Copy(bee.First());
while (T != TFinal && iter != iterMax)
{
newWorkBee.Clear();
workBee.Clear();
for (int i = 0; i < bee.Count; i++)
{
if (best.profit < bee[i].profit)
{
best.Copy(bee[i]);
}
}
for (int i = 0; i < bee.Count; i++)
{
if (Math.Exp(-Math.Abs(bee[i].profit - best.profit) / T) > rand.NextDouble())
{
workBee.Add(bee[i]);
}
}
workBee.Add(best);
//Step 4
foreach (Bee currBee in workBee)
{
tmp = new Bee(argCnt);
for (int i = 0; i < argCnt; i++)
{
tmp.point[i] = currBee.point[i] - getRandSign() * rand.NextDouble() * (currBee.point[i] - best.point[i]);
}
checkRange(ref tmp);
tmp.profit = getProfit(tmp);
newWorkBee.Add(tmp);
}
foreach (Bee currBee in workBee)
{
tmp = new Bee(argCnt);
for (int i = 0; i < argCnt; i++)
{
tmp.point[i] = best.point[i] - getRandSign() * rand.NextDouble() * (currBee.point[i] - best.point[i]);
}
checkRange(ref tmp);
tmp.profit = getProfit(tmp);
newWorkBee.Add(tmp);
}
newWorkBee.AddRange(workBee);
foreach (Bee currBee in newWorkBee)
{
if (best.profit < currBee.profit)
{
best.Copy(currBee);
}
}
//Step 5
double fullProfit = 0;
foreach (Bee currBee in newWorkBee)
{
fullProfit += currBee.profit;
}
double d;
double L;
bee.Clear();
for (int i = 0; i < newWorkBee.Count; i++)
{
d = newWorkBee[i].profit / fullProfit;
d += getRandSign() * rand.NextDouble() * wMax;
d = d > 1 ? 1 : d;
d = d < eMax ? 0 : d;
L = (d - eta * fullProfit / newWorkBee.Count) < 0 ? 0 : (d - eta * fullProfit / newWorkBee.Count);
if (L / beta > (gamma * fullProfit / newWorkBee.Count))
{
bee.Add(newWorkBee[i]); //danced bee are added
tmp = new Bee(argCnt);
for (int j = 0; j < argCnt; j++)
{
tmp.point[j] = newWorkBee[i].point[j] + range * rand.NextDouble() - range / 2;
}
checkRange(ref tmp);
tmp.profit = getProfit(tmp);
bee.Add(tmp);
}
else
{
tmp = getRandBee();
bee.Add(tmp);
//.........这里部分代码省略.........