本文整理汇总了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;
}
}
}
示例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;
}
}
示例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();
}
示例4: StatisticsWindow
public StatisticsWindow(IReadOnlyCollection<MozaicStatistic> mozaicStatisitics)
{
InitializeComponent();
MozaicStatisticsList.DataContext = mozaicStatisitics;
CountText.DataContext = mozaicStatisitics.Sum(x => x.Count);
}
示例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");
}