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


C# Grid.CopyTo方法代码示例

本文整理汇总了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);
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:12,代码来源:GridTest.cs

示例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);
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:13,代码来源:GridTest.cs

示例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);
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:54,代码来源:GridTest.cs


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