本文整理汇总了C#中GenericList.GetElementAtIndex方法的典型用法代码示例。如果您正苦于以下问题:C# GenericList.GetElementAtIndex方法的具体用法?C# GenericList.GetElementAtIndex怎么用?C# GenericList.GetElementAtIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericList
的用法示例。
在下文中一共展示了GenericList.GetElementAtIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: Main
static void Main()
{
//test Add and GetElementAtIndex
GenericList<string> list = new GenericList<string>(1);
list.Add("Zero");
list.Add("One");
string temp = list.GetElementAtIndex(1);
Console.WriteLine(temp);
list.Add("Two");
temp = list.GetElementAtIndex(2);
Console.WriteLine(temp);
Console.WriteLine();
//test Remove and Insert
list.Remove(1);
list.Insert(1, "Three");
temp = list.GetElementAtIndex(1);
Console.WriteLine(temp);
temp = list.GetElementAtIndex(2);
Console.WriteLine(temp);
Console.WriteLine();
//test Clear
list.Clear();
list.Add("Four");
list.Add("Five");
list.Add("Six");
temp = list.GetElementAtIndex(0);
Console.WriteLine(temp);
temp = list.GetElementAtIndex(1);
Console.WriteLine(temp);
temp = list.GetElementAtIndex(2);
Console.WriteLine(temp);
Console.WriteLine();
//test Find
Console.WriteLine(list.Find("Six"));
Console.WriteLine(list.Find("Seven"));
Console.WriteLine();
//test ToString
Console.WriteLine(list.ToString());
}