本文整理汇总了C#中GenericList.RemoveByIndex方法的典型用法代码示例。如果您正苦于以下问题:C# GenericList.RemoveByIndex方法的具体用法?C# GenericList.RemoveByIndex怎么用?C# GenericList.RemoveByIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericList
的用法示例。
在下文中一共展示了GenericList.RemoveByIndex方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
//Create new list of strings and show functionality
GenericList<string> myList = new GenericList<string>(10);
myList[0] = "My";
myList[1] = "name";
myList[2] = "is";
myList[3] = "Svetlin";
myList[4] = "Nakov";
Console.WriteLine(myList);
myList.Add("I like beer!");
Console.WriteLine(myList[5]);
myList.RemoveByIndex(2); // remove 'is'
Console.WriteLine(myList[2]); //print 'Svetlin'
myList.Insert(2, "my name");
Console.WriteLine(myList[2]);
Console.WriteLine(myList.IndexOfElement("name",0)); // print '1'
Console.WriteLine();
Console.WriteLine(myList);
myList[7] = "aaa";
myList[8] = "bbb";
myList[9] = myList.Max(myList[7], myList[8]);
Console.WriteLine(myList[9]); //print 'bbb'
//Create new list of strings and show functionality
GenericList<int> otherList = new GenericList<int>(3);
Console.WriteLine(otherList[0]);
}
示例2: Main
static void Main()
{
//Some tests. You can change values to check the correct work of the program.
GenericList<int> sampleList = new GenericList<int>(5);
sampleList.AddToGenericList(7);
sampleList.AddToGenericList(5);
sampleList.AddToGenericList(1);
sampleList.AddToGenericList(70);
sampleList.AddToGenericList(-7);
string listElements = sampleList.ToString();
Console.WriteLine("Sample list: {0}", listElements);
int element = sampleList.AcessByIndex(1);
Console.WriteLine("The value of the element on index 1 is {0}", element);
sampleList.RemoveByIndex(1);
Console.WriteLine("Sample list: {0}", sampleList);
sampleList.InsertAtPosition(2, 222);
Console.WriteLine("Sample list: {0}", sampleList);
int index = sampleList.FindByValue(70);
Console.WriteLine("1 is on index {0}", index);
int min = sampleList.Min();
int max = sampleList.Max();
Console.WriteLine("Min value - {0} \nMax value - {1}", min, max);
sampleList.ClearingList();
Console.WriteLine("Sample list: {0}", sampleList);
}
示例3: 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));
}
示例4: Main
static void Main()
{
var list = new GenericList<int>();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(4);
list.Add(3);
Console.WriteLine(list);
list[4] = 5;
Console.WriteLine(list);
list.Add(-5);
Console.WriteLine(list);
Console.WriteLine("list[2] = " + list[2]);
Console.WriteLine();
list.RemoveByIndex(list.Count - 1);
Console.WriteLine(list);
Console.WriteLine();
list.Insert(list.Count, 0);
Console.WriteLine(list);
Console.WriteLine();
Console.WriteLine(list.GetIndexByValue(5));
Console.WriteLine(list.IsContain(5));
Console.WriteLine("Max = " + list.Max());
Console.WriteLine("Min = " + list.Min());
Console.WriteLine();
list.RemoveAll();
Console.WriteLine("Empty list" + list);
Type type = typeof(GenericList<>);
object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
Console.WriteLine("GenericsList's version is {0}", ((VersionAttribute)allAttributes[0]).Version);
}
示例5: Main
static void Main(string[] args)
{
var list = new GenericList<int>();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(4);
list.Add(5);
list[4] = 19;
Console.WriteLine(list);
list.Add(-5);
Console.WriteLine(list);
Console.WriteLine("list[4] = " + list[4]);
list.RemoveByIndex(list.Count - 1);
Console.WriteLine(list);
Console.WriteLine("{0}",new string('-',60));
list.Insert(list.Count, 5);
Console.WriteLine(list);
Console.WriteLine("{0}", new string('-', 60));
Console.WriteLine(list.GetIndexByValue(5));
Console.WriteLine(list.IsContain(8));
Console.WriteLine("{0}", new string('-', 60));
Console.WriteLine("Highest = " + list.Max());
Console.WriteLine("Lowest = " + list.Min());
Console.WriteLine("{0}", new string('-', 60));
list.RemoveAll();
Console.WriteLine("After the List was Deleted = " + list);
Console.WriteLine("{0}", new string('-', 60));
Type type = typeof(GenericList<>);
object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), true);
}
示例6: Main
static void Main()
{
// Example shows how it works GenericList. You can change everything.
GenericList<int> myList = new GenericList<int>();
Console.WriteLine("--------GenericList--------");
Console.WriteLine("Capacity: {0} , Count: {1} ",myList.Capacity,myList.Count);
// Test Count,Capacity and Add
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Adding 20 elements...\n");
for (int i = 0; i < 20; i++)
{
myList.Add(i + 5);
}
Console.WriteLine("--------GenericList--------");
Console.WriteLine("Capacity: {0} , Count: {1} ", myList.Capacity, myList.Count);
Console.WriteLine(myList);
//Test RemoveAt ,InsertAt and FIndIndex
myList.InsertAtPosition(5, 1111);
myList.InsertAtPosition(6, 2222);
myList.InsertAtPosition(7, 3333);
myList.RemoveByIndex(10);
Console.WriteLine(Environment.NewLine);
Console.WriteLine("--------GenericList--------");
Console.WriteLine("Capacity: {0} , Count: {1} ", myList.Capacity, myList.Count);
Console.WriteLine(myList);
Console.WriteLine("\nThe element {0} is at {1} position.", 3333,myList.IndexOf(3333));
//Test Min and Max
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Min element is {0}",myList.Min());
Console.WriteLine("Max element is {0}", myList.Max());
Console.WriteLine();
}
示例7: Main
static void Main()
{
// Version:
var allAttributes = typeof(GenericList<>).GetCustomAttributes(typeof(VersionAttribute), false);
Console.WriteLine("Version: " + allAttributes[0]);
Console.WriteLine();
// Example 1:
Console.WriteLine("Example 1:");
GenericList<int> nums = new GenericList<int>(3);
nums.Add(2);
nums.Add(4);
nums.Add(6);
nums.Add(8);
nums.Add(7);
Console.WriteLine(nums);
Console.Write("Accessing element by index [2]: ");
Console.WriteLine(nums[2]);
Console.Write("Removing element by index [1]: ");
nums.RemoveByIndex(1);
Console.WriteLine(nums);
Console.Write("Inserting element by index [2], element = 10: ");
nums.InsertByIndex(2, 10);
Console.WriteLine(nums);
Console.Write("The element with the maximum value in the list: ");
Console.WriteLine(nums.Max());
Console.Write("The element with the minimum value in the list: ");
Console.WriteLine(nums.Min());
Console.Write("Finding element index by value: ");
Console.WriteLine(nums.FindElement(7));
Console.Write("Checking if the list contains a value: ");
Console.WriteLine(nums.Contains(-10));
Console.Write("Clearing the list: ");
nums.Clear();
Console.WriteLine(nums);
Console.WriteLine();
// Example 2:
Console.WriteLine("Example 2:");
GenericList<string> dogNames = new GenericList<string>(2);
dogNames.Add("Sharo");
dogNames.Add("Rex");
dogNames.Add("Blackie");
dogNames.Add("Rich");
dogNames.Add("Bella");
Console.WriteLine(dogNames);
Console.Write("Accessing element by index [3]: ");
Console.WriteLine(dogNames[3]);
Console.Write("Removing element by index [2]: ");
dogNames.RemoveByIndex(2);
Console.WriteLine(dogNames);
Console.Write("Inserting element by index [0], element = 'Izzy': ");
dogNames.InsertByIndex(0, "Izzy");
Console.WriteLine(dogNames);
Console.Write("The element with the maximum value in the list: ");
Console.WriteLine(dogNames.Max());
Console.Write("The element with the minimum value in the list: ");
Console.WriteLine(dogNames.Min());
Console.Write("Finding element index by value('Izzy'): ");
Console.WriteLine(dogNames.FindElement("Izzy"));
Console.Write("Checking if the list contains a value('Rich'): ");
Console.WriteLine(dogNames.Contains("Izzy"));
}