本文整理汇总了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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}