本文整理汇总了C#中GenericList.RemoveAtIndex方法的典型用法代码示例。如果您正苦于以下问题:C# GenericList.RemoveAtIndex方法的具体用法?C# GenericList.RemoveAtIndex怎么用?C# GenericList.RemoveAtIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericList
的用法示例。
在下文中一共展示了GenericList.RemoveAtIndex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
GenericList<int> testList = new GenericList<int>();
int chislo = 231;
testList.Add(chislo);
testList.Add(chislo);
testList.InsertAtPosition(1, 5);
testList.InsertAtPosition(1, 5);
testList.Add(chislo + 9);
int element = testList[0];
Console.WriteLine(element);
testList.RemoveAtIndex(3);
testList.InsertAtPosition(0, 124);
//testList.Clear();
testList.FindElementByValue(421);
testList.ToStringNew();
int min = testList.Min();
Console.WriteLine(min);
int max = testList.Max();
Console.WriteLine(max);
}
示例2: Main
static void Main()
{
GenericList<int> list1 = new GenericList<int>();
List<int> alabala=new List<int>();
alabala.Add(1);
list1.Add(4);
list1.Add(5);
list1.Add(6);
list1.Add(1);
list1.Add(3);
list1.Add(2);
Console.WriteLine("-====Printing Generic List====-");
Console.WriteLine(list1);
Console.WriteLine("-====End Of Printing====-");
Console.WriteLine();
Console.WriteLine("Min="+list1.Min());
Console.WriteLine("Max=" + list1.Max());
Console.WriteLine("Element in index 5 is",list1[5]);
Console.WriteLine("Removing element on at index 2");
list1.RemoveAtIndex(2);
Console.WriteLine("-====Printing Generic List====-");
Console.WriteLine(list1);
Console.WriteLine("-====End Of Printing====-");
Console.WriteLine();
Console.WriteLine("Inserting element 10 on at index 5");
list1.InsertAt(5,2);
Console.WriteLine("-====Printing Generic List====-");
Console.WriteLine(list1);
Console.WriteLine("-====End Of Printing====-");
Console.WriteLine();
Console.WriteLine("The index of element {0} is index {1}",6,list1.IndexOf(6));
Console.WriteLine("The List contains element 5 : {0}",list1.Contains(5));
Console.WriteLine("The List contains element 5 : {0}", list1.Contains(50));
Console.WriteLine("Min element of the list is {0}",list1.Min());
Console.WriteLine("Max element of the list is {0}", list1.Max());
Console.WriteLine("The max size of the list is {0}",list1.ActuallCapacity);
list1.Add(4);
list1.Add(5);
list1.Add(6);
list1.Add(1);
list1.Add(3);
list1.Add(2);
list1.Add(5);
list1.Add(6);
list1.Add(1);
list1.Add(3);
list1.Add(2);
Console.WriteLine("-====Printing Generic List====-");
Console.WriteLine(list1);
Console.WriteLine("-====End Of Printing====-");
Console.WriteLine("The max size of the list is {0}", list1.ActuallCapacity);
}
示例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: Main
static void Main(string[] args)
{
try
{
//Creating new list
GenericList<int> intList = new GenericList<int>(20);
//Overfill his capacity to make him auto grow
int maxCapacity = intList.Capacity;
for (int i = 1; i < maxCapacity * 2; i++)
{
intList.Add(i);
}
//Access elemtn by index
Console.WriteLine(intList[9]);
//Remove from index
intList.RemoveAtIndex(9);
//Insert new element at this position
intList.InsertAtPosition(9, 100);
//Look by value if the element is at this position
Console.WriteLine(intList.FindByValue(100));
//Find Min and Max value
Console.WriteLine(intList.Min());
Console.WriteLine(intList.Max());
//Use overriden method ToString()
Console.WriteLine(intList.ToString());
//Clear list
intList.Clear();
//And print again whith ToString()
Console.WriteLine(intList.ToString());
}
catch (Exception e)
{
Console.WriteLine("Error!" + e.Message);
}
}
示例7: Main
static void Main()
{
GenericList<int> test = new GenericList<int>();
test.AddElement(5);
test.AddElement(6);
test.AddElement(7);
test.AddElement(8);
test.AddElement(9);
//testing method add
Console.WriteLine(test);
//testing insert method
Console.WriteLine("Insert element 2 at position 4");
test.InsertElement(4, 2);
Console.WriteLine(test);
//testing method remove
Console.WriteLine("Removing element at pos 5");
test.RemoveAtIndex(5);
Console.WriteLine(test);
int result = test.AccessElement(3);
Console.WriteLine("Accessing element at index 3: ");
Console.WriteLine(result);
Console.WriteLine("Finding element by value '0': ");
Console.WriteLine(test.FindElementByValue(0));
Console.WriteLine("Clear!");
test.ClearingList();
Console.WriteLine(test);
Console.WriteLine();
Console.WriteLine("Doubling the size:");
for (int i = 1; i < 15; i++)
{
test.AddElement(i);
}
//test.AddElement(1);
Console.WriteLine(test);
//testing min max
Console.WriteLine("Biggest, smallest: ");
Console.WriteLine(test.Max<int>());
Console.WriteLine(test.Min<int>());
}
示例8: RemovingElementTest
public void RemovingElementTest()
{
GenericList<string> generic = new GenericList<string>(2);
generic.AddElement("Pesho");
generic.AddElement("Gosho");
generic.RemoveAtIndex(1);
Assert.AreEqual("[Pesho, (null)]", generic.ToString());
}
示例9: 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);
}
示例10: Main
static void Main()
{
var intList = new GenericList<int>(2);
Console.WriteLine("Creating an int generic list of length 2");
Console.WriteLine(new string('-', 30));
Console.WriteLine("Number of elements: {0}", intList.Count);
Console.WriteLine("Length: {0}", intList.Length);
intList.Add(3);
intList.Add(5);
Console.WriteLine(new string('-', 30));
Console.WriteLine("Adding 2 elements.");
Console.WriteLine(new string('-', 30));
Console.WriteLine("Number of elements: {0}", intList.Count);
Console.WriteLine("Length: {0}", intList.Length);
Console.WriteLine();
Console.WriteLine("Elements:");
Console.WriteLine(intList.ToString());
intList.Add(7);
Console.WriteLine(new string('-', 30));
Console.WriteLine("Adding another element.");
Console.WriteLine(new string('-', 30));
Console.WriteLine("Number of elements: {0}", intList.Count);
Console.WriteLine("Length: {0}", intList.Length);
Console.WriteLine();
Console.WriteLine("Elements:");
Console.WriteLine(intList.ToString());
intList.Clear();
Console.WriteLine(new string('-', 30));
Console.WriteLine("Clearing list.");
intList.InsertAt(0, 2);
intList.InsertAt(0, 2);
intList.InsertAt(1, 3);
Console.WriteLine(new string('-', 30));
Console.WriteLine("Inserting elements.");
Console.WriteLine(new string('-', 30));
Console.WriteLine("Number of elements: {0}", intList.Count);
Console.WriteLine("Length: {0}", intList.Length);
Console.WriteLine();
Console.WriteLine("Elements:");
Console.WriteLine(intList.ToString());
intList.RemoveAtIndex(0);
Console.WriteLine(new string('-', 30));
Console.WriteLine("Removing an element.");
Console.WriteLine(new string('-', 30));
Console.WriteLine("Number of elements: {0}", intList.Count);
Console.WriteLine("Length: {0}", intList.Length);
Console.WriteLine();
Console.WriteLine("Elements:");
Console.WriteLine(intList.ToString());
var element = intList.ElementAt(0);
Console.WriteLine(new string('-', 30));
Console.WriteLine("Element at index 0 is {0}.", element);
element = intList.IndexOf(3);
Console.WriteLine(new string('-', 30));
Console.WriteLine("The index of element 3 is {0}.", element);
var max = intList.Max();
Console.WriteLine(new string('-', 30));
Console.WriteLine("The max element is {0}.", max);
var min = intList.Min();
Console.WriteLine(new string('-', 30));
Console.WriteLine("The min element is {0}.", min);
}