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


C# Grid.ShrinkToFit方法代码示例

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


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

示例1: Resize

		[Test] public void Resize()
		{
			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.Resize(4, 4, Alignment.Center);
			Assert.AreEqual(16, grid.Capacity);
			Assert.AreEqual(4, grid.Width);
			Assert.AreEqual(4, grid.Height);
			CollectionAssert.AreEqual(new[] { 
				0, 0, 0, 0,
				0, 0, 1, 0,
				0, 2, 3, 0,
				0, 0, 0, 0 }, grid);

			grid.ShrinkToFit();
			CollectionAssert.AreEqual(new[] { 
				0, 1, 
				2, 3 }, grid);

			// Resizing with negative width or height should throw an exception
			Assert.Throws<ArgumentException>(() => grid.Resize(-1, 1));
			Assert.Throws<ArgumentException>(() => grid.Resize(1, -1));
			Assert.Throws<ArgumentException>(() => grid.Resize(-1, -1));
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:35,代码来源:GridTest.cs

示例2: AssumeRect

        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.ShrinkToFit();
            CollectionAssert.AreEqual(new[] {
                3 }, grid);
        }
开发者ID:nicstop,项目名称:duality,代码行数:29,代码来源:GridTest.cs

示例3: Resize

		[Test] public void Resize()
		{
			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.Resize(4, 4, Alignment.Center);
			Assert.AreEqual(16, grid.Capacity);
			Assert.AreEqual(4, grid.Width);
			Assert.AreEqual(4, grid.Height);
			CollectionAssert.AreEqual(new[] { 
				0, 0, 0, 0,
				0, 0, 1, 0,
				0, 2, 3, 0,
				0, 0, 0, 0 }, grid);

			grid.ShrinkToFit();
			CollectionAssert.AreEqual(new[] { 
				0, 1, 
				2, 3 }, grid);
		}
开发者ID:KSLcom,项目名称:duality,代码行数:30,代码来源:GridTest.cs

示例4: Basics

		[Test] public void Basics()
		{
			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);

			Assert.IsTrue(grid.Contains(3));
			Assert.AreEqual(new Point2(1, 1), grid.IndexOf(3));
			Assert.IsTrue(grid.Remove(3));
			Assert.IsFalse(grid.Remove(3));
			Assert.IsFalse(grid.Contains(3));
			Assert.AreEqual(new Point2(-1, -1), grid.IndexOf(3));
			CollectionAssert.AreEqual(new[] { 
				0, 1, 
				2, 0 }, grid);

			grid.Resize(4, 4, Alignment.Center);
			Assert.AreEqual(16, grid.Capacity);
			Assert.AreEqual(4, grid.Width);
			Assert.AreEqual(4, grid.Height);
			CollectionAssert.AreEqual(new[] { 
				0, 0, 0, 0,
				0, 0, 1, 0,
				0, 2, 0, 0,
				0, 0, 0, 0 }, grid);

			grid.ShrinkToFit();
			CollectionAssert.AreEqual(new[] { 
				0, 1, 
				2, 0 }, grid);

			grid.Clear();
			CollectionAssert.AreEqual(Enumerable.Repeat(0, grid.Capacity), grid);
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:43,代码来源:GridTest.cs

示例5: 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.ShrinkToFit();
			CollectionAssert.AreEqual(new[] { 
				3 }, 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:KSLcom,项目名称:duality,代码行数:38,代码来源:GridTest.cs


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