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


C# IReadOnlyCollection.Sum方法代码示例

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


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

示例1: CalculateTotal

        private static void CalculateTotal(FeatureTable general, IReadOnlyCollection<FeatureTable> all)
        {
            // special case
            var totals = general.Libraries.ToDictionary(
                library => library,
                library => all.Sum(t => t.GetScore(library))
            );

            var max = all.Sum(t => t.MaxScore);
            foreach (var total in totals) {
                var cell = general[total.Key, MetadataKeys.TotalFeature];
                var percent = 100 * ((double)total.Value / max);
                cell.DisplayValue = string.Format("{0:F0}%", percent);
                if (percent > 70) {
                    cell.State = FeatureState.Success;
                }
                else if (percent > 40) {
                    cell.State = FeatureState.Concern;
                }
                else {
                    cell.State = FeatureState.Failure;
                }
            }
        }
开发者ID:KallynGowdy,项目名称:net-feature-tests,代码行数:24,代码来源:Program.cs

示例2: Recalculate

        public override void Recalculate(IReadOnlyCollection<IPosition> windows)
        {
            if (windows.Count == 0)
                return;

            var top = DesktopHeight - (2 * VOffset + windows.Sum(w => w.Height) + (windows.Count - 1) * VOffset);

            foreach (var window in windows)
            {
                window.Left = 2 * HOffset;
                window.Top = top;
                window.Width = DesktopWidth - 4 * HOffset;

                top += window.Height + VOffset;
            }
        }
开发者ID:yakimovim,项目名称:desktop-toastr,代码行数:16,代码来源:PositionCalculatorFactory.cs

示例3: BuildDlxRow

        private static IImmutableList<int> BuildDlxRow(
            IReadOnlyCollection<Room> rooms,
            int numRows,
            int numCols,
            int maxValue,
            InternalRow internalRow)
        {
            Func<Coords, bool> isValidRowCol = coords =>
                coords.Col >= 0 && coords.Col < numCols &&
                coords.Row >= 0 && coords.Row < numRows;

            var localIsValidRowCol = isValidRowCol;

            var row = internalRow.Item1.Row;
            var col = internalRow.Item1.Col;
            var value = internalRow.Item2;
            var roomIndex = internalRow.Item3;

            Func<IEnumerable<int[]>> buildSecondaryColumns = () =>
            {
                var allRippleSecondaryColumns = Enumerable.Range(0, maxValue * 4).Select(_ => new int[numRows * numCols]).ToList();

                var rippleUpCoords = Enumerable.Range(row, value + 1)
                    .Select(r => new Coords(r, col))
                    .Where(localIsValidRowCol)
                    .ToList();

                var rippleDownCoords = Enumerable.Range(row - value, value + 1)
                    .Select(r => new Coords(r, col))
                    .Where(localIsValidRowCol)
                    .ToList();

                var rippleLeftCoords = Enumerable.Range(col - value, value + 1)
                    .Select(c => new Coords(row, c))
                    .Where(localIsValidRowCol)
                    .ToList();

                var rippleRightCoords = Enumerable.Range(col, value + 1)
                    .Select(c => new Coords(row, c))
                    .Where(localIsValidRowCol)
                    .ToList();

                var baseIndex = (value - 1) * 4;

                var rippleUpSecondaryColumns = allRippleSecondaryColumns[baseIndex];
                rippleUpCoords.ForEach(coords => rippleUpSecondaryColumns[coords.Row * numCols + coords.Col] = 1);

                var rippleDownSecondaryColumns = allRippleSecondaryColumns[baseIndex + 1];
                rippleDownCoords.ForEach(coords => rippleDownSecondaryColumns[coords.Row * numCols + coords.Col] = 1);

                var rippleLeftSecondaryColumns = allRippleSecondaryColumns[baseIndex + 2];
                rippleLeftCoords.ForEach(coords => rippleLeftSecondaryColumns[coords.Row * numCols + coords.Col] = 1);

                var rippleRightSecondaryColumns = allRippleSecondaryColumns[baseIndex + 3];
                rippleRightCoords.ForEach(coords => rippleRightSecondaryColumns[coords.Row * numCols + coords.Col] = 1);

                return allRippleSecondaryColumns;
            };

            var numRowColPrimaryColumns = numRows * numCols;
            var rowColPrimaryColumns = new int[numRowColPrimaryColumns];
            var rowColPrimaryColumnsIndex = row * numCols + col;
            rowColPrimaryColumns[rowColPrimaryColumnsIndex] = 1;

            var numCellWithinRoomPrimaryColumns = rooms.Sum(r => r.Cells.Count);
            var cellWithinRoomPrimaryColumns = new int[numCellWithinRoomPrimaryColumns];
            var cellWithinRoomPrimaryColumnsIndex = rooms.Take(roomIndex).Sum(r => r.Cells.Count) + value - 1;
            cellWithinRoomPrimaryColumns[cellWithinRoomPrimaryColumnsIndex] = 1;

            var secondaryColumns = buildSecondaryColumns();

            var allColumns = new[] { rowColPrimaryColumns, cellWithinRoomPrimaryColumns }.Concat(secondaryColumns);

            return allColumns
                .SelectMany(columns => columns)
                .ToImmutableList();
        }
开发者ID:taylorjg,项目名称:RippleEffectDlx,代码行数:77,代码来源:PuzzleSolver.cs

示例4: StatisticsWindow

 public StatisticsWindow(IReadOnlyCollection<MozaicStatistic> mozaicStatisitics)
 {
     InitializeComponent();
     MozaicStatisticsList.DataContext = mozaicStatisitics;
     CountText.DataContext = mozaicStatisitics.Sum(x => x.Count);
 }
开发者ID:MasterPieceCode,项目名称:YangManic,代码行数:6,代码来源:StatisticsWindow.xaml.cs

示例5: GetAvgRating

 private static string GetAvgRating(IReadOnlyCollection<ProductReview> reviews)
 {
     decimal sum = reviews.Sum(review => review.Rating.GetValueOrDefault());
     decimal avg = sum / reviews.Count;
     return avg.ToString("F1");
 }
开发者ID:jovan-juranovic,项目名称:big-room-repo,代码行数:6,代码来源:IndexController.cs


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