本文整理汇总了C#中GenericList.InsertAtIndex方法的典型用法代码示例。如果您正苦于以下问题:C# GenericList.InsertAtIndex方法的具体用法?C# GenericList.InsertAtIndex怎么用?C# GenericList.InsertAtIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericList
的用法示例。
在下文中一共展示了GenericList.InsertAtIndex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
//GenericList<string> test = new GenericList<string>();
//test.AddElement("Testing");
//test.AddElement("string");
//Console.WriteLine(test.ToString()); //before inserting a new element
//test.InsertAtIndex(0, "sf");
//Console.WriteLine(test.ToString()); //after inserting a new element
//var testAccessByIndex = test.AccessByIndex(1);
//Console.WriteLine("I am the element at index 1 = {0}", testAccessByIndex);
GenericList<double> anotherTest = new GenericList<double>();
anotherTest.AddElement(1);
anotherTest.AddElement(2);
anotherTest.AddElement(3);
anotherTest.AddElement(4);
Console.WriteLine("Numbers = {0}", anotherTest.ToString());
var minElement = anotherTest.Min();
Console.WriteLine("MIN element is {0}", minElement);
var maxElement = anotherTest.Max();
Console.WriteLine("MAX element is {0}", maxElement);
Console.WriteLine("Element[1] using indexer = {0}", anotherTest[1]);
Console.WriteLine("Element AccessByIndex(1) = {0}", anotherTest.AccessByIndex(1));
anotherTest.RemoveByIndex(1);
Console.WriteLine("Removed element[1], result = {0}", anotherTest.ToString());
anotherTest.InsertAtIndex(1, 5);
Console.WriteLine("Insert 5 at index[1],result = {0}",anotherTest.ToString());
anotherTest.ClearList();
Console.WriteLine("Elements ClearList() = {0}", anotherTest.ToString());
Console.WriteLine("Check if list contains 0: {0}",anotherTest.FindByValue(0));
}
示例2: Main
static void Main()
{
var someList = new GenericList<double>(4);
for (int i = 0; i < 5; i++)
{
someList.AddElement(i + 2.5);
}
someList.InsertAtIndex(0, -12.5);
someList.InsertAtIndex(0, -16.3);
for (int i = 0; i < someList.Count; i++)
{
Console.WriteLine(someList[i]);
}
someList.Clear();
Console.WriteLine(someList.Count);
}
示例3: Main
static void Main()
{
GenericList<int> list = new GenericList<int>(10);
for (int i = 0; i < 6; i++)
{
list.Add(i);
}
Console.WriteLine(list.ToString());
Console.WriteLine("List state after initialization: ");
for (int i = 0; i < list.COUNT; i++)
{
Console.Write("{0} ", list.GetAtIndex(i));
}
list.RemoveAtIndex(2);
Console.WriteLine("\nList state after removing element at index {0}: ", list.INDEX);
for (int i = 0; i < list.COUNT; i++)
{
Console.Write("{0} ", list.GetAtIndex(i));
}
list.InsertAtIndex(7, 13);
Console.WriteLine("\nList state after inserting element at index {0}: ", list.INDEX);
for (int i = 0; i < list.COUNT; i++)
{
Console.Write("{0} ", list.GetAtIndex(i));
}
list.Add(14);
Console.WriteLine("\nList state after adding an element: ");
for (int i = 0; i < list.COUNT; i++)
{
Console.Write("{0} ", list.GetAtIndex(i));
}
list.Add(99);
Console.WriteLine("\nList state after adding another element: ");
for (int i = 0; i < list.COUNT; i++)
{
Console.Write("{0} ", list.GetAtIndex(i));
}
Console.WriteLine("\n" + list.ToString());
Console.WriteLine("MAX: {0}", GenericList<int>.Max(list));
Console.WriteLine("MIN: {0}", GenericList<int>.Min(list));
Console.WriteLine(list.GetAtIndex(list.GetByValue(4)));
}
示例4: Main
static void Main()
{
var list = new GenericList<int>();
list.Add(10);
list.Add(20);
list.Add(30);
Console.WriteLine(list); //[10, 20, 30]
Console.WriteLine("Max: {0}", list.Max()); //30
Console.WriteLine("Min: {0}", list.Min()); //10
Console.WriteLine(list[0]); //10
Console.WriteLine(list[1]); //20
//Exception:
//Console.WriteLine(list[-1]);
//Console.WriteLine(list[3]);
list[1] = 150;
Console.WriteLine(list);
Console.WriteLine(list.Contains(150)); //true
Console.WriteLine(list.Contains(1000)); //false
Console.WriteLine(list.IndexOf(30)); //2
Console.WriteLine(list.IndexOf(1000)); //-1
list.InsertAtIndex(0, 1000);
Console.WriteLine(list.ToString()); //[1000, 10, 150, 30]
list.RemoveAtIndex(0);
Console.WriteLine(list); //[10, 150, 30]
//Exception:
//list.RemoveAtIndex(-1);
//list.RemoveAtIndex(3);
//list.InsertAtIndex(-1, 40);
//list.InsertAtIndex(3, 33);
Console.WriteLine(list.Pop()); //30
Console.WriteLine(list); //[10, 150]
list.Push(-60);
Console.WriteLine(list); //[10, 150, -60]
list.Clear();
Console.WriteLine(list); //[]
}
示例5: Main
static void Main(string[] args)
{
GenericList<string> myStrList = new GenericList<string>();
myStrList.Add("ivan");
myStrList.Add("asen");
myStrList.Add("gosho");
myStrList.Add("pesho");
myStrList.InsertAtIndex("bobi", 0);
myStrList.RemoveAtIndex(1);
Console.WriteLine(myStrList);
myStrList.GetVersion();
}
示例6: InsertWithAutoGrowTest
public void InsertWithAutoGrowTest()
{
GenericList<string> generic = new GenericList<string>(2);
generic.AddElement("Pesho");
generic.AddElement("Gosho");
generic.AddElement("Kircho");
generic.InsertAtIndex("Vlado", 0);
generic.InsertAtIndex("Blagoi", 1);
Assert.AreEqual("[Vlado, Blagoi, Pesho, Gosho, Kircho, (null), (null), (null)]", generic.ToString());
}
示例7: InsertTest
public void InsertTest()
{
GenericList<string> generic = new GenericList<string>(2);
generic.AddElement("Pesho");
generic.AddElement("Gosho");
generic.AddElement("Kircho");
generic.InsertAtIndex("Vlado", 0);
Assert.AreEqual("[Vlado, Pesho, Gosho, Kircho]", generic.ToString());
}
示例8: Main
// Some simple tests. They are OPTINAL.
public static void Main()
{
// Create an integer list and add few elements. Also prints the size after each add.
GenericList<int> list1 = new GenericList<int>(1);
Console.WriteLine("Type of the list: {0}", list1.GetType());
Console.WriteLine();
Console.WriteLine("Current size of the list: {0}", list1.Size);
Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
Console.WriteLine("Adding 1 element...");
list1.Add(1);
Console.WriteLine("Current elements in the list:\n{0}", list1.ToString());
Console.WriteLine("Current size of the list: {0}", list1.Size);
Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
Console.WriteLine("Adding 1 element...");
list1.Add(2);
Console.WriteLine("Current elements in the list:\n{0}", list1.ToString());
Console.WriteLine("Current size of the list: {0}", list1.Size);
Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
Console.WriteLine("Adding 1 element...");
list1.Add(3);
Console.WriteLine("Current elements in the list:\n{0}", list1.ToString());
Console.WriteLine("Current size of the list: {0}", list1.Size);
Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
Console.WriteLine();
// Print the maximal element
Console.WriteLine("Maximal element:");
Console.WriteLine(list1.Max());
Console.WriteLine();
// Print an element by it's index
Console.WriteLine("Printing the element at position 1 (starting from 0):\n{0}", list1[1].ToString());
Console.WriteLine();
// Remove an element by it's index
Console.WriteLine("Removing the element at position 1 (starting from 0)\nand printing the result:");
list1.RemoveAtIndex(1);
Console.WriteLine();
Console.WriteLine("Current size of the list: {0}", list1.Size);
Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
Console.WriteLine("Current elements in the list:\n{0}", list1.ToString());
Console.WriteLine();
// Clearing the list (the size won't change)
Console.WriteLine("Clearing the list...");
list1.Clear();
Console.WriteLine("Current size of the list: {0}", list1.Size);
Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
Console.WriteLine("Current elements in the list:\n{0}", list1.ToString());
Console.WriteLine();
// Inserting an element at position 0. This will throw an exeption
// because you can't use InsertAtIndex for empty list.
Console.WriteLine("Exception will be thrown now...");
list1.InsertAtIndex(0, 5);
}