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


C# List.Sum方法代码示例

本文整理汇总了C#中Common.List.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# List.Sum方法的具体用法?C# List.Sum怎么用?C# List.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Common.List的用法示例。


在下文中一共展示了List.Sum方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TotalCost

 public TotalsBO TotalCost(List<ReceiptItemBO> receipt)
 {
     return new TotalsBO()
     {
         DiscountSum = Math.Round(receipt.Sum(r => r.WellnessDiscount), 2),
         TaxSum = Math.Round(receipt.Sum(r => r.ItemTax), 2),
         TotalSum = Math.Round(receipt.Sum(r => r.ItemTotal), 2)
     };
 }
开发者ID:alisalamin,项目名称:RecipeCalc,代码行数:9,代码来源:RecipeCalculator.cs

示例2: GetCorrelogram

        public static List<double> GetCorrelogram(List<double> excerpt, int k)
        {
            // sum of all elements
            double sum = excerpt.Sum();
            // init lsum (only left elements) and rsum (only right elements)
            // theirs size will be decreased
            double lsum = sum, rsum = sum;
            List<double> crl = new List<double> { 1 };
            for (int i = 1; i <= k; i++)
            {
                // subtract last left element from rsum
                rsum -= excerpt[i - 1];
                // subtract last right element from lsum
                lsum -= excerpt[excerpt.Count - i];
                // reduction of sum by dividing by N-K
                double rusum = rsum / (excerpt.Count - i), lusum = lsum / (excerpt.Count - i);
                // abv is expression in numerator

                double abv = 0, lund = 0, rund = 0;
                for (int j = 0; j < excerpt.Count - i; j++)
                {
                    abv += (excerpt[j] - lusum) * (excerpt[j + i] - rusum);
                    lund += (excerpt[j] - lusum) * (excerpt[j] - lusum);
                    rund += (excerpt[j + i] - rusum) * (excerpt[j + i] - rusum);
                }
                double und = Math.Sqrt(rund * lund);
                double val = abv == und ? 1.0 : abv / und;
                crl.Add(val);
            }
            return crl;
        }
开发者ID:SanyoGorbunov,项目名称:univer-projects,代码行数:31,代码来源:RandomExcerptChecker.cs

示例3: Main

        private static void Main()
        {
            int num = Helpers.ValidateInputAsInt("How many numbers you would like to enter: ");
            List<double> numbers = new List<double>();

            // Fill array with numbers
            for (int i = 0; i < num; i++)
            {
                numbers.Add(Helpers.ValidateInputAsDouble("Enter value " + (i + 1) + ": "));
            }

            // Use of List methods
            Console.WriteLine("Minimal number is : {0}", numbers.Min());
            Console.WriteLine("Maximal number is : {0}", numbers.Max());
            Console.WriteLine("Sum number is : {0}", numbers.Sum());
            Console.WriteLine("Average number is : {0}", numbers.Average());
        }
开发者ID:deyantodorov,项目名称:TelerikAcademy,代码行数:17,代码来源:NumbersOperation.cs

示例4: cosumeRecordAnalysis


//.........这里部分代码省略.........
                    }

                    if (listUserConsume == null || (listUserConsume != null && listUserConsume.Count < 1))
                    {
                        continue;
                    }

                    //以对冲记录产生的时间升序排列,时间早的靠前
                    List<PreConsumeRecord_pcs_Info> listUserHedge = userItem.OrderBy(x => x.pcs_dConsumeDate).ToList();
                    if (listUserHedge != null && listUserHedge.Count > 0)
                    {
                        for (int i = 0; i < listUserHedge.Count; i++)
                        {
                            List<ConsumeRecord_csr_Info> listConsumeComp = new List<ConsumeRecord_csr_Info>();
                            if (i > 0 && i == listUserHedge.Count - 1)
                            {
                                //对冲记录数大于0,且为最后一条记录时,找出是否存在打卡记录在最后一条对冲记录和倒数第二条对冲记录之间
                                listConsumeComp = listUserConsume.Where(x => x.csr_dConsumeDate <= listUserHedge[i].pcs_dConsumeDate && x.csr_dConsumeDate > listUserHedge[i - 1].pcs_dConsumeDate).ToList();
                            }
                            else if (i < listUserHedge.Count - 1)
                            {
                                listConsumeComp = listUserConsume.Where(x => x.csr_dConsumeDate < listUserHedge[i + 1].pcs_dConsumeDate && x.csr_dConsumeDate >= listUserHedge[i].pcs_dConsumeDate).ToList();
                            }
                            else if (i == 0 && listUserHedge.Count == 1)
                            {
                                listConsumeComp = listUserConsume.Where(x => x.csr_dConsumeDate <= listUserHedge[i].pcs_dConsumeDate).ToList();
                            }

                            if (listConsumeComp == null)
                                continue;

                            if (listConsumeComp.Count > 1)
                            {
                                decimal fComp = Math.Abs(listUserHedge[i].pcs_fCost) - Math.Abs(listConsumeComp.Sum(x => x.csr_fConsumeMoney));
                                if (fComp <= 0)
                                {
                                    listUserHedge[i].pcs_lIsSettled = true;
                                    listUserHedge[i].pcs_dSettleTime = DateTime.Now;
                                    listUpdate_PreCost.Add(listUserHedge[i]);
                                }
                                else
                                {
                                    listUserHedge[i].pcs_dConsumeDate = DateTime.Now;
                                    listUserHedge[i].pcs_fCost = fComp;
                                    listUpdate_PreCost.Add(listUserHedge[i]);
                                }

                                foreach (ConsumeRecord_csr_Info item in listConsumeComp)
                                {
                                    ConsumeRecord_csr_Info consumeHedge = listUpdate_Consume.Find(x => x.csr_cRecordID == item.csr_cRecordID);
                                    if (consumeHedge == null)
                                    {
                                        consumeHedge = listUpdate_UnMealConsume.Find(x => x.csr_cRecordID == item.csr_cRecordID);
                                        consumeHedge.csr_lIsSettled = true;
                                        consumeHedge.csr_dSettleTime = DateTime.Now;
                                        listUpdate_Consume.Add(consumeHedge);
                                    }
                                    else
                                    {
                                        consumeHedge.csr_lIsSettled = true;
                                        consumeHedge.csr_dSettleTime = DateTime.Now;
                                    }
                                }
                            }
                            else
                            {
开发者ID:Klutzdon,项目名称:SIOTS_HHZX,代码行数:67,代码来源:UserAccountFundSyncService.cs

示例5: Replace

        /// <summary>  
        /// 二进制替换,如果没有替换则返回原数组对像的复本.  
        /// </summary>  
        /// <param name="sourceByteArray">源数据</param>  
        /// <param name="replaces">需要替换的数据集合</param>  
        public static byte[] Replace(byte[] sourceByteArray, List<HexReplaceEntity> replaces)
        {
            //创建新数据多出1字节
            int newArrayLen =
                (int)
                    ((replaces.Sum(p => p.newValue.Length) / (double)replaces.Sum(p => p.oldValue.Length)) *
                     sourceByteArray.Length) + 1;
            //得到数组长度
            newArrayLen = Math.Max(newArrayLen, sourceByteArray.Length);
            //新的最后结果数组
            byte[] newByteArray = new byte[newArrayLen];
            //新数组的当前索引
            int curIndex = 0;
            bool find = false;
            //替换数据替换
            for (int x = 0; x < sourceByteArray.Length; x++)
            {

                foreach (HexReplaceEntity rep in replaces)
                {
                    //查找要替换的数据
                    if (sourceByteArray[x] == rep.oldValue[rep.oldCurindex])
                    {
                        if (rep.oldCurindex == 0)
                        {
                            rep.start = x;
                        }
                        if (rep.oldCurindex == rep.oldValue.Length - 1)
                        {
                            rep.end = x;
                            rep.oldCurindex = 0;
                        }
                        else
                        {
                            rep.oldCurindex++;
                        }
                    }
                    else
                    {
                        rep.oldCurindex = 0;
                        newByteArray[curIndex] = sourceByteArray[x];
                        find = false;
                    }
                    //数据查找完成
                    if (rep.start != -1 && rep.end != -1)
                    {
                        find = true;
                        if (rep.newValue.Length >= rep.oldValue.Length)
                        {
                            //复制替换数据
                            Buffer.BlockCopy(rep.newValue, 0, newByteArray, curIndex, rep.newValue.Length);
                            //计算新数组的偏移量
                            curIndex += rep.newValue.Length;
                        }
                        else
                        //由大字节替换为少字节时出现了问题
                        {
                            curIndex -= rep.end - rep.start;
                            //复制替换数据
                            Buffer.BlockCopy(rep.newValue, 0, newByteArray, curIndex, rep.newValue.Length);
                            //计算新数组的偏移量
                            curIndex += rep.newValue.Length;
                        }
                        //重新设置需要复制索引的索引
                        rep.start = rep.end = -1;
                        break;
                    }
                }
                if (!find)
                {
                    curIndex++;
                }
            }

            //处理返回结果
            byte[] result = null;
            //if (curIndex != 0)
            //{
            //    result = new byte[curIndex];
            //    Buffer.BlockCopy(newByteArray, 0, result, 0, result.Length);
            //}
            //else
            //{
            //    result = new byte[sourceByteArray.Length];
            //    Buffer.BlockCopy(sourceByteArray, 0, result, 0, result.Length);
            //}
            if (curIndex != 0)
                return newByteArray;
            else
                return sourceByteArray;
        }
开发者ID:orichisonic,项目名称:Program,代码行数:96,代码来源:StringReplacer.cs

示例6: CalculateExpectedValue

 public static double CalculateExpectedValue(List<double> excerpt)
 {
     return excerpt.Sum() / excerpt.Count;
 }
开发者ID:SanyoGorbunov,项目名称:univer-projects,代码行数:4,代码来源:EstimationHelper.cs

示例7: CalculateDispersion

 public static double CalculateDispersion(List<double> excerpt)
 {
     double ev = CalculateExpectedValue(excerpt);
     return excerpt.Sum(val => (val - ev) * (val - ev)) / (excerpt.Count - 1);
 }
开发者ID:SanyoGorbunov,项目名称:univer-projects,代码行数:5,代码来源:EstimationHelper.cs

示例8: btFind_Click

        protected void btFind_Click(object sender, EventArgs e)
        {
            DateTime? orderFrom = ctrlDatePickerFrom.SelectedDate;
            DateTime? orderTo = ctrlDatePickerTo.SelectedDate;

            int orderId = 0;
            int.TryParse(txtOrderCode.Text, out orderId);

            int custId = 0;
            int.TryParse(ctrlCustomerSelect.CustomerId, out custId);

            int productId = 0;
            int.TryParse(ddlProduct.SelectedValue, out productId);

            int shipMethodId = 0;
            int.TryParse(ddlShipping.SelectedValue, out shipMethodId);

            int depositMethodId = 0;
            int.TryParse(ddlDeposit.SelectedValue, out depositMethodId);

            int orderDetailStatusId = 0;
            int.TryParse(ddlOrderDetailStatus.SelectedValue, out orderDetailStatusId);

            int busManId = 0;
            int.TryParse(ddlBusinessManId.SelectedValue,out busManId);

            int designerManId = 0;
            int.TryParse(ddlDesingerId.SelectedValue, out designerManId);

            List<OrderStatusEnum> orderStatus = new List<OrderStatusEnum>();
            foreach(ListItem i in cblOrderStatus.Items)
            {
                if (i.Selected)
                {
                    orderStatus.Add((OrderStatusEnum)int.Parse(i.Value));
                }
            }

            List<int> printingTypeIds = ctrlPrintingTypeSelect.SelectedValues;

            OrderSearch orderSearchObj = new OrderSearch()
            {
                OrderFrom = orderFrom,
                OrderTo = orderTo,
                OrderId= orderId,
                CustId = custId,
                ProductId = productId,
                ShipMethodId = shipMethodId,
                DepositMethodId = depositMethodId,
                OrderDetailStatus = (OrderItemStatusEnum)orderDetailStatusId,
                OrderStatus = orderStatus,
                BusManId = busManId,
                DesignerManId = designerManId,
                PrintingTypeIds = printingTypeIds
            };

            List<OrderBO> orders = this.OrderService.GetOrders(orderSearchObj);
            grvOrders.DataSource = orders;
            grvOrders.DataBind();

            lbNumberOfOrders.Text = orders.Count.ToString();
            lbOrderTotal.Text = orders.Sum(o => o.OrderTotal).ToString("C0");

            lbNotCompletedNumberOfOrders.Text = orders.Where(o=>o.OrderStatus == OrderStatusEnum.NotCompleted).Count().ToString();
            lbNotCompletedOrderTotal.Text = orders.Where(o => o.OrderStatus == OrderStatusEnum.NotCompleted).Sum(o => o.OrderTotal).ToString("C0");

            lbCompletedNumberOfOrders.Text = orders.Where(o => o.OrderStatus == OrderStatusEnum.Completed).Count().ToString();
            lbCompletedOrderTotal.Text = orders.Where(o => o.OrderStatus == OrderStatusEnum.Completed).Sum(o => o.OrderTotal).ToString("C0");

            lbFailedNumberOfOrders.Text = orders.Where(o => o.OrderStatus == OrderStatusEnum.IsFailed).Count().ToString();
            lbFailedOrderTotal.Text = orders.Where(o => o.OrderStatus == OrderStatusEnum.IsFailed).Sum(o => o.OrderTotal).ToString("C0");

            List<ProductApprovedBO> failedProductsResult = new List<ProductApprovedBO>();
            foreach (OrderBO o in orders)
            {
                List<ProductApprovedBO> failedProducts = this.OrderService.GetFailedProductByOrderId(o.OrderId);
                foreach (ProductApprovedBO pa in failedProducts)
                {
                    failedProductsResult.Add(pa);
                }
            }

            lbFailedOrderDetailTotal.Text = failedProductsResult.Sum(fd => fd.Total).ToString("C0");

            lbOverdueNumberOfOrders.Text = orders.Where(o => o.OrderStatus == OrderStatusEnum.Overdue).Count().ToString();
            lbOverdueOrderTotal.Text = orders.Where(o => o.OrderStatus == OrderStatusEnum.Overdue).Sum(o => o.OrderTotal).ToString("C0");
            var overdueOrders = orders.Where(o => o.OrderStatus == OrderStatusEnum.Overdue);
            decimal overdueOrderDetailTotal = 0;
            foreach (OrderBO o in overdueOrders)
            {
                foreach (OrderItemlBO od in o.OrderItems)
                {
                    if (od.OrderItemStatus == OrderItemStatusEnum.Overdue)
                    {
                        overdueOrderDetailTotal += od.Quantity * od.Price;
                    }
                }
            }
            lbOverdueOrderDetailTotal.Text = overdueOrderDetailTotal.ToString("C0");
        }
开发者ID:nguyentu1982,项目名称:inthudo,代码行数:100,代码来源:Orders.ascx.cs

示例9: ControlarImprimirEnvase

        private int? ControlarImprimirEnvase(List<LINEA_VENTA> ImprimirLineasEnGrilla)
        {
            //controlo si existen envases
            if (!ImprimirLineasEnGrilla.Any(x => x.ENV_ID != null))
                return null;

            List<LINEA_VENTA> listaEnvase = new List<LINEA_VENTA>();
            decimal subTotal = 0;
            decimal total = 0;
            foreach (var item in ImprimirLineasEnGrilla)
            {
                if (item.ENV_ID != null)
                {
                    listaEnvase.Add(item);
                }
            }

            subTotal = listaEnvase.Sum(x => x.LIN_TOTAL);
            total = subTotal;

            var comprobante = cTIPO_COMPROBANTES.ObtenerPorDescripcion(Constantes.ValeEnvase);
            int nroComprobante = (int)comprobante.TIC_ULTIMONUMERO;
            comprobante.TIC_ULTIMONUMERO = nroComprobante + 1;
            cTIPO_COMPROBANTES.Modificacion(comprobante);

            var nroCompEnvase = comprobante.TIC_ULTIMONUMERO;

            if (!ImpresoraOK)
            {
                MostrarMensajeInformativo(string.Format("Por falla de impresora se generó la devolución de envase Nro: {0}", nroCompEnvase));
                return nroCompEnvase;
            }
            else
            {
                #region IMPRIME DOCUMENTO NO FISCAL

                var noFiscal = new DocumentoNoFiscalTicket();

                noFiscal.DescripcionCabecera1 = "---------------------------";
                noFiscal.DescripcionCabecera2 = "-- Devolucion de Envases";
                noFiscal.DescripcionCabecera3 = string.Format("-- Nro: {0}", TipoComprobante.TIC_ULTIMONUMERO);
                noFiscal.DescripcionCabecera4 = "---------------------------";

                noFiscal.items = new List<DocumentoNoFiscalTicketItem>();
                foreach (LINEA_VENTA LineaEnGrilla in listaEnvase)
                {
                    var item = new DocumentoNoFiscalTicketItem();
                    item.DescripcionItem = (LineaEnGrilla.LIN_DESCRESUMIDA.Length > 27) ? LineaEnGrilla.LIN_DESCRESUMIDA.Substring(0, 27) : LineaEnGrilla.LIN_DESCRESUMIDA.ToString();
                    item.Cantidad = LineaEnGrilla.LIN_CANTIDAD.ToString("0.000");
                    item.PrecioUnitario = LineaEnGrilla.LIN_PRECIOUNIDAD.ToString("0.000");
                    noFiscal.items.Add(item);
                }

                //DESCUENTO
                noFiscal.DescuentoDescripcion = "";
                noFiscal.DescuentoMonto = "";

                //PAGO
                noFiscal.PagoDescripcionExtra = "";
                noFiscal.PagoDescripcion = "";

                noFiscal.SubTotalMonto = subTotal.ToString("0.000");
                noFiscal.TotalMonto = total.ToString("0.000");

                //CIERRE
                noFiscal.DescripcionPie1 = "Para retornar los envases";
                noFiscal.DescripcionPie2 = "debe presentar el comprobante.";
                noFiscal.DescripcionPie3 = "";

                var retornoImpresion = frmImpresoraFiscal.DocumentoNoFiscalTicket(noFiscal);
                if (retornoImpresion < 0)
                    return nroCompEnvase;

                //MostrarMensajeInformativo("Se imprimió correctamente Nº: " + retornoImpresion);

                #endregion
            }

            return nroCompEnvase;
        }
开发者ID:maurojuze,项目名称:super-mercado-v2,代码行数:80,代码来源:frmVENTAS.cs


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