本文整理汇总了C#中SinglyLinkedList.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# SinglyLinkedList.CopyTo方法的具体用法?C# SinglyLinkedList.CopyTo怎么用?C# SinglyLinkedList.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SinglyLinkedList
的用法示例。
在下文中一共展示了SinglyLinkedList.CopyTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyToTest
public void CopyToTest()
{
// NOTE: the Add method, adds them to the front of the list, therefore the list is in reverse
var list = new SinglyLinkedList<int> { 1, 0, -1 };
var expected = new int[] { -1, 0, 1 };
var actual = new int[list.Count];
list.CopyTo(actual, 0);
CollectionAssert.AreEqual(expected, actual, "The arrays do not match");
}
示例2: TestSinglyLinkedListIndexer
public void TestSinglyLinkedListIndexer()
{
SinglyLinkedList<string> list = new SinglyLinkedList<string>();
list.Add("One");
list.Add("Two");
list.Add("Three");
list[0] = "Zero";
string[] array = new string[list.Count];
list.CopyTo(array);
Assert.AreEqual("Zero, Two, Three", string.Join(", ", array));
}
示例3: TestSinglyLinkedListInsert_InsertAtTheEnd
public void TestSinglyLinkedListInsert_InsertAtTheEnd()
{
SinglyLinkedList<string> list = new SinglyLinkedList<string>();
list.Add("One");
list.Add("Two");
list.Add("Three");
list[0] = "Zero";
list.Insert(3, "Ten");
string[] array = new string[list.Count];
list.CopyTo(array);
Assert.AreEqual("Zero, Two, Three, Ten", string.Join(", ", array));
}
示例4: TestCopyToIndex
public void TestCopyToIndex()
{
var expected = new int[4] { 0, 1, 2, 3 };
var list = new SinglyLinkedList<int>(new int[2] { 2, 3 });
var actual = new int[4] { 0, 1, -1, -1 };
list.CopyTo(actual, 2);
CollectionAssert.AreEqual(expected, actual);
}
示例5: TestCopyTo0
public void TestCopyTo0()
{
var expected = new int[4] { 0, 1, 2, 3 };
var list = new SinglyLinkedList<int>(expected);
var actual = new int[4];
list.CopyTo(actual, 0);
CollectionAssert.AreEqual(expected, actual);
}
示例6: CopyToInvalidIndexTest
public void CopyToInvalidIndexTest()
{
SinglyLinkedList<int> sll = new SinglyLinkedList<int> {10, 20, 30};
int[] myArray = new int[sll.Count];
sll.CopyTo(myArray, -1);
}
示例7: CopyToIndexGteThanArrayTest
public void CopyToIndexGteThanArrayTest()
{
SinglyLinkedList<int> sll = new SinglyLinkedList<int> {10, 20, 30};
int[] myArray = new int[sll.Count];
sll.CopyTo(myArray, 2);
}
示例8: ArrayCopyWithDefinedStartIndexTest
public void ArrayCopyWithDefinedStartIndexTest()
{
SinglyLinkedList<int> sll = new SinglyLinkedList<int> {10, 20, 30};
int[] actual = new int[10];
sll.CopyTo(actual, 6);
Assert.AreEqual(10, actual[6]);
Assert.AreEqual(20, actual[7]);
Assert.AreEqual(30, actual[8]);
}
示例9: CopyToInvalidIndexTest
public void CopyToInvalidIndexTest([PexAssumeUnderTest]int[] melements, int position)
{
PexAssume.IsTrue(position >= -1 && position < melements.Length);
PexAssume.IsTrue(melements.Length > 0);
SinglyLinkedList<int> sll = new SinglyLinkedList<int>(melements);
int[] myArray = new int[sll.Count + position];
sll.CopyTo(myArray, position);
int compPosition = position;
if (position == -1)
compPosition = 0;
for (int i = position, j = 0; i < sll.Count; i++)
{
PexAssert.AreEqual(myArray[i], melements[i]);
}
}