本文整理汇总了C#中GenericList.AccessByIndex方法的典型用法代码示例。如果您正苦于以下问题:C# GenericList.AccessByIndex方法的具体用法?C# GenericList.AccessByIndex怎么用?C# GenericList.AccessByIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericList
的用法示例。
在下文中一共展示了GenericList.AccessByIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
示例2: Main
private static void Main()
{
GenericList<string> list = new GenericList<string>();
//adding an element
list.Add("0 - primeren");
list.Add("1 - listttt");
list.Add("2 - asfsdfsdfsdfd");
//accessing element by index
string s = list.AccessByIndex(1);
Console.WriteLine(s);
Console.WriteLine("------------------");
//removing element by index
list.RemoveAt(1);
list.Print();
Console.WriteLine("----------------");
//inserting element at given position
list.InsertAt("inserttttt", 2);
list.Print();
Console.WriteLine("-----------------");
//clearing the list
list.Clear();
//check if the list contains a value
list.Add("edno");
list.Add("dve");
list.Add("tri");
bool b = list.Contains("dve");
Console.WriteLine(b);
Console.WriteLine("---------------");
//print the entire list
list.Print();
Console.WriteLine("----------------");
//auto-grow
//GenericList<string> list3 = new GenericList<string>() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17" };
//list3.Print();
//Console.WriteLine("-------------------");
GenericList<int> list4 = new GenericList<int> {1, 2, -3, 4, 50, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
list4.Print();
Console.WriteLine("--------");
//min
var min = list4.Min();
Console.WriteLine(min);
//max
var max = list4.Max();
Console.WriteLine(max);
Console.WriteLine("------------");
//Problem 4 - Generic List Version
Type type = typeof (GenericList<>);
object[] allAttributes = type.GetCustomAttributes(false);
foreach (VersionAttribute attr in allAttributes)
{
Console.WriteLine("Version: {0}", attr.Version);
}
}