本文整理汇总了C#中IReadOnlyCollection.Take方法的典型用法代码示例。如果您正苦于以下问题:C# IReadOnlyCollection.Take方法的具体用法?C# IReadOnlyCollection.Take怎么用?C# IReadOnlyCollection.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReadOnlyCollection
的用法示例。
在下文中一共展示了IReadOnlyCollection.Take方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}