本文整理汇总了C#中GenericList.RemoveElementAtIndex方法的典型用法代码示例。如果您正苦于以下问题:C# GenericList.RemoveElementAtIndex方法的具体用法?C# GenericList.RemoveElementAtIndex怎么用?C# GenericList.RemoveElementAtIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericList
的用法示例。
在下文中一共展示了GenericList.RemoveElementAtIndex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
GenericList<int> listInt = new GenericList<int>();
//Adding elements
listInt.Add(99);
listInt.Add(8);
listInt.Add(0);
listInt.Add(-7);
listInt.Add(-9);
Console.WriteLine(new string('=', 50));
Console.WriteLine("Test Adding elements");
Console.WriteLine("{0}", listInt);
Console.WriteLine();
//Inserting Elements
listInt.AddElementAtIndex(2, -22);
listInt.AddElementAtIndex(0, -21);
Console.WriteLine(new string('=', 50));
Console.WriteLine("Test Inserting elements");
Console.WriteLine("{0}", listInt);
Console.WriteLine();
//Removing elements
listInt.RemoveElementAtIndex(0);
listInt.RemoveElementAtIndex(2);
Console.WriteLine(new string('=', 50));
Console.WriteLine("Test Removing elements");
Console.WriteLine("{0}", listInt);
Console.WriteLine();
//Index of element by its value
Console.WriteLine(new string('=', 50));
Console.WriteLine("Test Index of elements");
Console.WriteLine( "{0}", listInt.IndexOf(8));
Console.WriteLine();
//Min item
Console.WriteLine(new string('=', 50));
Console.WriteLine("Test finding min item");
Console.WriteLine("{0}", listInt.Min<int>());
Console.WriteLine();
//Max item
Console.WriteLine(new string('=', 50));
Console.WriteLine("Test finding max item");
Console.WriteLine("{0}", listInt.Max<int>());
Console.WriteLine();
}
示例2: Main
static void Main()
{
GenericList<int> list = new GenericList<int>();
Console.WriteLine("Adding numbers:");
list.AddElement(3);
list.AddElement(5);
list.AddElement(12);
Console.WriteLine(list + Environment.NewLine); // Print
Console.WriteLine("Inserting [-3] at position [2]");
list.InsertElementAt(2, -3);
Console.WriteLine(list + Environment.NewLine); // Print
Console.WriteLine("Removing element at position [1]");
list.RemoveElementAtIndex(1);
Console.WriteLine(list + Environment.NewLine);
Console.WriteLine("Search for number [-3]");
Console.WriteLine(list.FindElementValue(-3) + Environment.NewLine);
Console.WriteLine("STATISTICS");
Console.WriteLine("Elements count: {0}", list.Count);
Console.WriteLine("Min element: {0}", list.Min());
Console.WriteLine("Max element: {0}", list.Max());
list.ClearList();
Console.WriteLine();
}
示例3: 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);
}
示例4: 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);
}
示例5: 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
示例6: 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();
}
示例7: Main
static void Main()
{
GenericList<int> intList = new GenericList<int>();
intList.AddElement(5);
intList.AddElement(10);
intList.AddElement(15);
Console.WriteLine(intList);
intList.InsertElementAt(1, 20);
Console.WriteLine(intList);
intList.RemoveElementAtIndex(2);
Console.WriteLine(intList);
intList.AddElement(50);
intList.AddElement(60);
Console.WriteLine(intList);
Console.WriteLine("Elements Count: {0}", intList.Count);
Console.WriteLine("Min: {0}", intList.Min());
Console.WriteLine("Max: {0}", intList.Max());
Console.WriteLine(new String('-', 30));
}
示例8: 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());
}
示例9: Main
static void Main(string[] args)
{
// create an instance of the GenericList class;
GenericList<int> list = new GenericList<int>();
// add elements to the List using the method AddElement in GenericList class
list.AddElement(1);
list.AddElement(5);
list.AddElement(10);
list.AddElement(15);
list.AddElement(20);
//print the List - usint the overriden ToString() in GenericList class
Console.WriteLine("List elements are: ");
Console.WriteLine(list);
// access the element by given index using the method AccessElementAtPosition in GenericList class
int index = 2;
Console.Write("Element at index {0} is: ", index);
Console.WriteLine(list.AccessElementAtPosition(index));
Console.WriteLine();
// insert an element at given position
index = 0;
int num = 1000000000;
list[index] = num;
Console.WriteLine("Assign {0} to index {1}", num, index);
Console.WriteLine(list);
// add new element at given index
//all elements after the given index are replaced to the right
// the length of the array is increased by one
index = 2;
num = 22222;
list.AddElementAtIndex(num, index);
Console.WriteLine("Add new element with value {0} at index {1}", num, index);
Console.WriteLine("Note that all element after the given index are replaced to the right \nand the length of the array is increased by one.");
Console.WriteLine(list);
// remove the element at given index
// all elements after the given index are replaced to the left
// the length of the array is decreased by one
index = 3;
Console.WriteLine("Remove the element at index {0}", index);
Console.WriteLine("Note that all element after the given index are replaced to the left \nand the length of the array is decreased by one.");
list.RemoveElementAtIndex(3);
Console.WriteLine(list);
// find element by its value using the method IndexOfElement in GenericList
int elementValue = 5;
Console.Write("The index of element with value {0} is: ", elementValue);
Console.WriteLine(list.IndexOfElement(elementValue));
// gets the Minimal element of the list using the GetMin() method in the GenericList class
Console.Write("Minimal element of the array is: ");
Console.WriteLine(list.GetMin());
// gets the Maximal element of the list using the GetMax() method in the GenericList class
Console.Write("Maximal element of the array is: ");
Console.WriteLine(list.GetMax());
// clear the list and assing the default value of T type to each index
Console.WriteLine("Clear the list");
list.ClearAllElements();
Console.WriteLine(list);
}
示例10: Main
static void Main(string[] args) // JUST PRESS F5!!! :)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("TEST 1 \"Point3D\":");
Console.ResetColor();
Console.WriteLine();
Point3D A = new Point3D(2, 8, 6);
Point3D B = new Point3D(5, 3, 5);
Console.WriteLine("Printing Points A and B:");
Console.WriteLine(A);
Console.WriteLine(B);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("END TEST 1 \"Point3D\"");
Console.WriteLine();
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("TEST 2 \"DistanceFinder\":");
Console.ResetColor();
Console.WriteLine();
Console.Write("Distance: ");
Console.WriteLine(DistanceFinder.CalcDistance(A, B));
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("END TEST 2 \"DistanceFinder\"");
Console.WriteLine();
Console.ResetColor();
Path newLine = new Path();
newLine.AddPoint(A);
newLine.AddPoint(B);
newLine.AddPoint(new Point3D(9, 6, 5));
Point3D C = newLine.PathPoints[2];
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("TEST 3 \"Load Points from file\":");
Console.ResetColor();
Console.WriteLine();
Console.WriteLine("Loaded points from file \"LoadFile.txt\":");
Path loadedPath = PathStorage.LoadPath();
foreach (Point3D point in loadedPath.PathPoints)
{
Console.WriteLine(point);
}
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("END TEST 3 \"Load Points from file\"");
Console.WriteLine();
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("TEST 4 \"Save Points to file\":");
Console.ResetColor();
Console.WriteLine();
PathStorage.SavePath(newLine);
Console.WriteLine("Points A, B and C are saved in SaveFile.txt");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("END TEST 4 \"Save Points to file\"");
Console.WriteLine();
Console.ResetColor();
GenericList<string> theList = new GenericList<string>();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("TEST 5 \"GenericList\":");
Console.ResetColor();
Console.WriteLine();
theList.AddElement("1");
theList.AddElement("3");
Console.Write("Printed elements from \"TheList\": ");
Console.WriteLine(theList);
Console.WriteLine();
Console.WriteLine("Adding \"2\" in position 1!");
theList.InsertElement(1, "2");
Console.Write("Printed elements from \"TheList\": ");
Console.WriteLine(theList);
Console.WriteLine();
Console.WriteLine("Removing element with index 1!");
theList.RemoveElementAtIndex(1);
Console.Write("Printed elements from \"TheList\": ");
Console.WriteLine(theList);
Console.WriteLine();
Console.WriteLine("Clearing \"TheList\"!");
theList.Clear();
Console.Write("Printed elements from \"TheList\": ");
Console.WriteLine(theList);
//.........这里部分代码省略.........