本文整理汇总了C#中RawList.ShrinkToFit方法的典型用法代码示例。如果您正苦于以下问题:C# RawList.ShrinkToFit方法的具体用法?C# RawList.ShrinkToFit怎么用?C# RawList.ShrinkToFit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RawList
的用法示例。
在下文中一共展示了RawList.ShrinkToFit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Basics
[Test] public void Basics()
{
RawList<int> intList = new RawList<int>();
intList.Add(10);
intList.AddRange(new int[] { 17, 42, 94 });
Assert.AreEqual(4, intList.Count);
Assert.IsTrue(intList.Contains(42));
Assert.AreEqual(2, intList.IndexOf(42));
CollectionAssert.AreEqual(new int[] { 10, 17, 42, 94 }, intList);
CollectionAssert.AreEqual(new int[] { 10, 17, 42, 94 }, intList.Data.Take(4));
intList.ShrinkToFit();
Assert.AreEqual(intList.Count, intList.Capacity);
intList.Remove(42);
Assert.AreEqual(3, intList.Count);
Assert.IsTrue(!intList.Contains(42));
Assert.AreEqual(-1, intList.IndexOf(42));
CollectionAssert.AreEqual(new int[] { 10, 17, 94 }, intList);
CollectionAssert.AreEqual(new int[] { 10, 17, 94 }, intList.Data.Take(3));
intList.Insert(1, 100);
CollectionAssert.AreEqual(new int[] { 10, 100, 17, 94 }, intList);
CollectionAssert.AreEqual(new int[] { 10, 100, 17, 94 }, intList.Data.Take(4));
intList.InsertRange(2, new int[] { 150, 200, 250, 300 });
CollectionAssert.AreEqual(new int[] { 10, 100, 150, 200, 250, 300, 17, 94 }, intList);
CollectionAssert.AreEqual(new int[] { 10, 100, 150, 200, 250, 300, 17, 94 }, intList.Data.Take(8));
intList.Clear();
Assert.AreEqual(0, intList.Count);
Assert.IsTrue(!intList.Contains(94));
}