public void TestToArray() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) { list.Add(j); } short[] a1 = list.ToArray(); Assert.AreEqual(a1.Length, list.Count); for (short j = 0; j < 1000; j++) { Assert.AreEqual(a1[j], list.Get(j)); } short[] a2 = new short[list.Count]; short[] a3 = list.ToArray(a2); Assert.AreSame(a2, a3); for (short j = 0; j < 1000; j++) { Assert.AreEqual(a2[j], list.Get(j)); } short[] ashort = new short[list.Count - 1]; short[] aLong = new short[list.Count + 1]; short[] a4 = list.ToArray(ashort); short[] a5 = list.ToArray(aLong); Assert.IsTrue(a4 != ashort); Assert.IsTrue(a5 != aLong); Assert.AreEqual(a4.Length, list.Count); for (short j = 0; j < 1000; j++) { Assert.AreEqual(a3[j], list.Get(j)); } Assert.AreEqual(a5.Length, list.Count); for (short j = 0; j < 1000; j++) { Assert.AreEqual(a5[j], list.Get(j)); } }