public void InserItemAtPosition() { var list = new SimpleList<int>() { 1, 2, 3, 4 }; list.Insert(4, 5); var list2 = new SimpleList<int>() { 1, 2, 3, 4, 5 }; CollectionAssert.Equals(list2, list); }
public void Insert() { SimpleList <string> strings = new SimpleList <string>(3, true); strings.Add("first"); strings.Add("second"); strings.Insert(2, "fourth"); strings.Insert(2, "third"); strings.Insert(4, "fifth"); Assert.AreEqual(0, strings.IndexOf("first")); Assert.AreEqual(1, strings.IndexOf("second")); Assert.AreEqual(2, strings.IndexOf("third")); Assert.AreEqual(3, strings.IndexOf("fourth")); Assert.AreEqual(4, strings.IndexOf("fifth")); Assert.ThrowsException <ArgumentOutOfRangeException>(() => { strings.Insert(6, "sixth"); }); }
static void Main(string[] args) { SimpleList<int> _strings = new SimpleList<int>(); _strings.Add(1); _strings.Add(2); _strings.Add(3); _strings.Add(4); _strings.Add(5); var count = _strings.Count; var number5 = _strings[4]; _strings[4] = 6; var number6 = _strings[4]; _strings.Insert(4, 5); var number1 = _strings.RemoveAt(0); _strings.Clear(); }
static void Main() { SimpleList test = new SimpleList(); // Populate the List Console.WriteLine("Populate the List"); test.Add("one"); test.Add("two"); test.Add("three"); test.Add("four"); test.Add("five"); test.Add("six"); test.Add("seven"); test.Add("eight"); test.PrintContents(); Console.WriteLine(); // Remove elements from the list Console.WriteLine("Remove elements from the list"); test.Remove("six"); test.Remove("eight"); test.PrintContents(); Console.WriteLine(); // Add an element to the end of the list Console.WriteLine("Add an element to the end of the list"); test.Add("nine"); test.PrintContents(); Console.WriteLine(); // Insert an element into the middle of the list Console.WriteLine("Insert an element into the middle of the list"); test.Insert(4, "number"); test.PrintContents(); Console.WriteLine(); // Check for specific elements in the list Console.WriteLine("Check for specific elements in the list"); Console.WriteLine("List contains \"three\": {0}", test.Contains("three")); Console.WriteLine("List contains \"ten\": {0}", test.Contains("ten")); }
public void Insert(int index, T item) { data.Insert(index, item); OnItemInserted(item, up, index); }