本文整理汇总了C#中Grid.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# Grid.CopyTo方法的具体用法?C# Grid.CopyTo怎么用?C# Grid.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grid
的用法示例。
在下文中一共展示了Grid.CopyTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyConvert
[Test] public void CopyConvert()
{
Grid<int> sourceGrid = new Grid<int>(4, 4);
Grid<float> targetGrid = new Grid<float>(4, 4);
sourceGrid.Fill(7, 1, 1, 2, 2);
sourceGrid.CopyTo(targetGrid);
CollectionAssert.AreEqual(new[] {
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 7.0f, 7.0f, 0.0f,
0.0f, 7.0f, 7.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f }, targetGrid);
}
示例2: CopySelect
[Test] public void CopySelect()
{
Grid<int> sourceGrid = new Grid<int>(4, 4);
Grid<string> targetGrid = new Grid<string>(4, 4);
sourceGrid.Fill(7, 1, 1, 2, 2);
targetGrid.Fill("Keep", 0, 0, 2, 2);
sourceGrid.CopyTo(targetGrid, selector: (i, s) => s != "Keep" ? i.ToString() : s);
CollectionAssert.AreEqual(new[] {
"Keep", "Keep", "0", "0",
"Keep", "Keep", "7", "0",
"0", "7", "7", "0",
"0", "0", "0", "0" }, targetGrid);
}
示例3: AssumeRect
[Test] public void AssumeRect()
{
Grid<int> grid = new Grid<int>(2, 2);
grid[0, 0] = 0;
grid[1, 0] = 1;
grid[0, 1] = 2;
grid[1, 1] = 3;
Assert.AreEqual(4, grid.Capacity);
Assert.AreEqual(2, grid.Width);
Assert.AreEqual(2, grid.Height);
CollectionAssert.AreEqual(new[] {
0, 1,
2, 3 }, grid);
grid.AssumeRect(1, 1, 4, 4);
Assert.AreEqual(16, grid.Capacity);
Assert.AreEqual(4, grid.Width);
Assert.AreEqual(4, grid.Height);
CollectionAssert.AreEqual(new[] {
3, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0 }, grid);
grid.AssumeRect(-1, -2, 4, 4);
Assert.AreEqual(16, grid.Capacity);
Assert.AreEqual(4, grid.Width);
Assert.AreEqual(4, grid.Height);
CollectionAssert.AreEqual(new[] {
0, 0, 0, 0,
0, 0, 0, 0,
0, 3, 0, 0,
0, 0, 0, 0 }, grid);
grid.AssumeRect(2, 0, 4, 4);
Assert.AreEqual(16, grid.Capacity);
Assert.AreEqual(4, grid.Width);
Assert.AreEqual(4, grid.Height);
CollectionAssert.AreEqual(new[] {
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0 }, grid);
Random rnd = new Random();
grid.Resize(4, 4);
for (int i = 0; i < grid.Capacity; i++) grid.RawData[i] = rnd.Next();
Grid<int> grid2 = new Grid<int>(6, 6);
grid.CopyTo(grid2, 1, 1);
Grid<int> grid3 = new Grid<int>(grid);
grid3.AssumeRect(-1, -1, 6, 6);
CollectionAssert.AreEqual(grid2, grid3);
}