本文整理汇总了C#中GenericList.InsertElementAtIndex方法的典型用法代码示例。如果您正苦于以下问题:C# GenericList.InsertElementAtIndex方法的具体用法?C# GenericList.InsertElementAtIndex怎么用?C# GenericList.InsertElementAtIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericList
的用法示例。
在下文中一共展示了GenericList.InsertElementAtIndex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
var list = new GenericList<int>();
var attributes = typeof(GenericList<>).GetCustomAttributes(typeof(VersionAttribute), false);
Console.WriteLine("Version: {0}", ((VersionAttribute)attributes[0]).Version + Environment.NewLine);
list.AddElement(3);
list.AddElement(5);
list.AddElement(12);
Console.WriteLine("Add elements: {0}", list + Environment.NewLine);
Console.WriteLine("Get element at index [0] \r\n{0}",
list[0] + Environment.NewLine);
list.RemoveElementAtIndex(1);
Console.WriteLine("Remove element at index [1] \r\n{0}",
list + Environment.NewLine);
list.InsertElementAtIndex(2, -3);
Console.WriteLine("Insert '-3' at index [2] \r\n{0}",
list + Environment.NewLine);
Console.WriteLine("Find element '-3' \r\n{0}",
list.FindElementByValue(-3) + Environment.NewLine);
Console.WriteLine("STATISTICS \r\nElements count: {0} \r\nMin element: {1} \r\nMax element: {2}",
list.Count, list.Min(), list.Max() + Environment.NewLine);
list.ClearList();
Console.WriteLine("Clear the list \r\nList count: {0}", list.Count);
}
示例2: Main
public static void Main()
{
//testing bellow all of the defined in GenericList
GenericList<int> listTesting = new GenericList<int>(1);
listTesting.AddElement(3);
listTesting.AddElement(2);
listTesting.AddElement(-100);
listTesting.AddElement(1);
listTesting.AddElement(6);
Console.WriteLine(listTesting);
listTesting.RemoveElementAtIndex(1);
Console.WriteLine(listTesting);
listTesting.InsertElementAtIndex(0, 21);
Console.WriteLine(listTesting);
Console.WriteLine(listTesting.FindElementByValue(7));
Console.WriteLine(listTesting.Max());
Console.WriteLine(listTesting.Min());
listTesting.ClearList();
Console.WriteLine(listTesting);
}
示例3: Main
public static void Main()
{
GenericList<int> exampleGeneric = new GenericList<int>(3);
Console.WriteLine("GenericList capacity = " + exampleGeneric.Capacity);
Console.WriteLine("ToString method result = " + exampleGeneric.ToString());
Console.WriteLine(new string('=', 30));
exampleGeneric.Add(3);
exampleGeneric.Add(4);
exampleGeneric.Add(7);
exampleGeneric.Add(12);
Console.WriteLine("ToString method result after adding elements = " + exampleGeneric.ToString());
Console.WriteLine(new string('=', 30));
Console.WriteLine("The element at index 0 is " + exampleGeneric.GetItemAtIndex(0));
Console.WriteLine("The element at index 1 is " + exampleGeneric.GetItemAtIndex(1));
Console.WriteLine("The element at index 2 is " + exampleGeneric.GetItemAtIndex(2));
Console.WriteLine("The element at index 3 is " + exampleGeneric.GetItemAtIndex(3));
Console.WriteLine(new string('=', 30));
exampleGeneric.RemoveElementAtIndex(0);
Console.WriteLine("ToString method result after removing element at index 0 = " + exampleGeneric.ToString());
exampleGeneric.RemoveElementAtIndex(2);
Console.WriteLine("ToString method result after removing element at index 2 = " + exampleGeneric.ToString());
Console.WriteLine(new string('=', 30));
exampleGeneric.InsertElementAtIndex(3, 0);
Console.WriteLine("ToString method result after inserting value of 3 at index 0 = " + exampleGeneric.ToString());
exampleGeneric.InsertElementAtIndex(12, 2);
Console.WriteLine("ToString method result after inserting value of 12 at index 1 = " + exampleGeneric.ToString());
Console.WriteLine(new string('=', 30));
Console.WriteLine("The index of 12 is " + exampleGeneric.FindElement(12));
Console.WriteLine("The index of 3 is " + exampleGeneric.FindElement(3));
Console.WriteLine("The index of 4 is " + exampleGeneric.FindElement(4));
Console.WriteLine(new string('=', 30));
Console.WriteLine("The min value is " + exampleGeneric.Min());
Console.WriteLine("The max value is " + exampleGeneric.Max());
Console.WriteLine(new string('=', 30));
exampleGeneric.Clear();
Console.WriteLine("ToString method result after clearing = " + exampleGeneric.ToString());
Console.WriteLine(new string('=', 30));
}
开发者ID:AyrFX,项目名称:Telerik-Academy-2015-Object-Oriented-Programming-Homeworks,代码行数:45,代码来源:GenericClassDemo.cs
示例4: Main
public static void Main(string[] args)
{
//test GenericList
Console.WriteLine("Test \"GenericList\"");
GenericList<int> list = new GenericList<int>(5);
int length = list.Capacity;
for (int i = 0; i < length; i++)
{
list.Add(i + 5);
}
Console.WriteLine("list -> element at index 1 = {0}", list.GetElement(1));
Console.WriteLine();
Console.WriteLine("list -> {0}", list);
Console.WriteLine();
list.InsertElementAtIndex(3, 7);
list.InsertElementAtIndex(3, 7);
list.InsertElementAtIndex(3, 7);
list.InsertElementAtIndex(3, 7);
list.InsertElementAtIndex(3, 7);
list.InsertElementAtIndex(3, 7);
list.InsertElementAtIndex(3, 7);
Console.WriteLine("list -> {0}", list);
Console.WriteLine();
list.Add(7);
Console.WriteLine("list -> {0}", list);
Console.WriteLine();
list.RemoveElementAtIndex(3);
list.RemoveElementAtIndex(3);
list.RemoveElementAtIndex(3);
list.RemoveElementAtIndex(3);
list.RemoveElementAtIndex(3);
list.RemoveElementAtIndex(3);
list.RemoveElementAtIndex(list.Count - 1);
Console.WriteLine("list -> {0}", list);
Console.WriteLine();
Console.WriteLine("find index of value 4 -> {0}", list.FindByValue(4));
Console.WriteLine("list -> {0}", list);
Console.WriteLine();
Console.WriteLine("list min-element -> {0}", list.Min());
Console.WriteLine("list max-element -> {0}", list.Max());
Console.WriteLine();
Console.WriteLine("Clear list:");
list.Clear();
Console.WriteLine("list -> {0}", list);
Console.WriteLine();
}
示例5: Main
static void Main()
{
GenericList<int> nums = new GenericList<int>(2);
// Add elements
nums.AddElement(5);
nums.AddElement(10);
nums.AddElement(1);
nums.AddElement(8);
Console.WriteLine("List after adding elements: " + nums + "\n");
// Remove elements
nums.RemoveElement(1);
nums.RemoveElement(2);
Console.WriteLine("List after removing elements: " + nums + "\n");
// show element at index
Console.WriteLine("Element at given index: " + nums.ElementAtIndex(0) + "\n");
// insert elements at index
nums.InsertElementAtIndex(10, 50);
Console.WriteLine(nums);
nums.InsertElementAtIndex(1, 999);
Console.WriteLine(nums + "\n");
// find index of given element
nums.FindIndex(999);
nums.FindIndex(444);
Console.WriteLine();
// check if list contains element
Console.WriteLine(nums.Contains(999));
Console.WriteLine(nums.Contains(444));
Console.WriteLine();
// find min element
Console.WriteLine("Min element is: " + GenericList<int>.Min(10, 7) + "\n");
// find max element
Console.WriteLine("Max element is: " + GenericList<string>.Max("Albena", "Ruse"));
// clear list
nums.ClearList();
Console.WriteLine(nums);
}
示例6: Main
static void Main()
{
//Create generic list
GenericList<int> myList = new GenericList<int>(2);
//Add elemnets
myList.AddElement(30);
myList.AddElement(2);
myList.AddElement(3);
Console.WriteLine(myList);
//Access element by index
Console.Write("The element at index 0 is: ");
Console.WriteLine(myList.GetElementAtIndex(0));
Console.WriteLine();
//Remove element at certain index
myList.RemoveElementAtIndex(1);
Console.WriteLine("The element at index 1 has been removed!");
Console.WriteLine(myList);
//Insert element at certain index
myList.InsertElementAtIndex(1, 800);
Console.WriteLine("The element at index 1 has been inserted!");
Console.WriteLine(myList);
//Find index of value 800 and 3000
Console.Write("The value 800 has index of: ");
Console.WriteLine(myList.FindElement(800));
Console.Write("The value 3000 has index of: ");
Console.WriteLine(myList.FindElement(3000));
//Min element in list
Console.WriteLine();
Console.Write("The min element is:");
Console.WriteLine(myList.MinElement());
//Max element in list
Console.Write("The max element is:");
Console.WriteLine(myList.MaxElement());
}