本文整理汇总了C#中GenericList.GetElement方法的典型用法代码示例。如果您正苦于以下问题:C# GenericList.GetElement方法的具体用法?C# GenericList.GetElement怎么用?C# GenericList.GetElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericList
的用法示例。
在下文中一共展示了GenericList.GetElement方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: Main
static void Main()
{
GenericList<int> a = new GenericList<int>(34);
//Console.WriteLine(a.Capacity);
a.AddElement(6);
a.AddElement(7);
a.AddElement(8);
//Console.WriteLine(a.Count);
//Console.WriteLine(a.GetElement(2));
a.RemoveElement(2);
for (int i = 0; i < a.Count; i++)
{
Console.WriteLine(a.GetElement(i));
}
Console.WriteLine();
a.InsertElement(24, 5);
for (int i = 0; i < a.Count; i++)
{
Console.WriteLine(a.GetElement(i));
}
Console.WriteLine();
//a.Clear();
//for (int i = 0; i < a.Count; i++)
//{
// Console.WriteLine(a.GetElement(i));
//}
Console.WriteLine();
Console.WriteLine(a.GetIndexOf(7));
}
示例3: Main
static void Main(string[] args) {
IGenericList<string> stringList = new GenericList<string>();
stringList.Add("Hello");
stringList.Add("World");
stringList.Add("!");
Console.WriteLine(stringList.Count); // 3
Console.WriteLine(stringList.Contains("Hello")); // true
Console.WriteLine(stringList.IndexOf("Hello")); // 0
Console.WriteLine(stringList.GetElement(1)); // World
IGenericList<double> doubleList = new GenericList<double>();
doubleList.Add(0.2);
doubleList.Add(0.7);
Console.ReadLine();
}
示例4: Main
static void Main(string[] args)
{
IntegerList listOfIntegers = new IntegerList(1);
listOfIntegers.Add(1);
listOfIntegers.Add(2);
listOfIntegers.Add(3);
listOfIntegers.Add(4);
listOfIntegers.Add(5); // lista je [1,2,3,4,5]
printList(listOfIntegers);
// Mičemo prvi element liste.
listOfIntegers.RemoveAt(0); // Lista je [2,3,4,5]
printList(listOfIntegers);
// Mičemo element liste čija je vrijednost "5".
listOfIntegers.Remove(5); // Lista je [2,3,4]
printList(listOfIntegers);
Console.WriteLine(listOfIntegers.Count); // 3
Console.WriteLine(listOfIntegers.Remove(100)); // false, nemamo element u vrijednosti 100
Console.WriteLine(listOfIntegers.RemoveAt(5)); // false, nemamo ništa na poziciji 5
// Brišemo sav sadržaj kolekcije
listOfIntegers.Clear();
Console.WriteLine(listOfIntegers.Count);
IGenericList<string> stringList = new GenericList<string>();
stringList.Add("Hello");
stringList.Add("World");
stringList.Add("!");
Console.WriteLine(stringList.Count); // 3
Console.WriteLine(stringList.Contains("Hello")); // true
Console.WriteLine(stringList.IndexOf("Hello")); // 0
Console.WriteLine(stringList.GetElement(1)); // World
IGenericList<double> doubleList = new GenericList<double>();
doubleList.Add(0.2);
doubleList.Add(0.7);
foreach (string str in stringList)
{
Console.WriteLine(str);
}
Console.ReadLine();
}
示例5: Main
static void Main(string[] args)
{
IGenericList<string> stringList = new GenericList<string>();
stringList.Add("Hello");
stringList.Add("World");
stringList.Add("!");
Console.WriteLine("String List: " + stringList.ToString());
Console.WriteLine(stringList.Count); // 3
Console.WriteLine(stringList.Contains("Hello")); // true
Console.WriteLine(stringList.IndexOf("Hello")); // 0
Console.WriteLine(stringList.GetElement(1) + "\n"); // World
foreach (string value in stringList)
{
Console.WriteLine(value);
}
Console.ReadLine();
}
示例6: Main
public static int Main()
{
GenericList<int> list = new GenericList<int>(20);
for (int i = 0; i <= 45; i++)
{
list.AddElement(i + 5);
}
list.RemoveElement(5);
Console.Write("Elements: ");
for (int i = 0; i <= list.Size() - 1; i++)
{
Console.Write(list.GetElement((uint)i));
if (i < list.Size() - 1)
{
Console.Write(",");
}
}
Console.WriteLine("\n{0}",list.FindElementByVal(40));
Console.WriteLine(list.Min());
Console.WriteLine(list.Max());
Console.WriteLine(list.ToString());
return 0;
}
示例7: Main
static void Main()
{
//Problem 1-4 tests
Point3D point = new Point3D(2, 3, 4);
Console.WriteLine(point.ToString());
Point3D staticPoint = Point3D.StartPoint;
Console.WriteLine(staticPoint.ToString());
Point3D a = new Point3D(0, 1, 2);
Point3D b = new Point3D(2, 3, 4);
Path g = new Path();
g.AddPoint(a);
g.AddPoint(b);
PathStorage.SavePath(g,"bla");
//Problem 5-8 tests
GenericList<int> myList = new GenericList<int>(3);
myList.AddElement(1);
myList.AddElement(2);
myList.AddElement(3);
Console.WriteLine();
Console.WriteLine("add elements:");
for (int i = 0; i < myList.Elements.Length; i++)
{
Console.WriteLine(myList.Elements[i]);
}
Console.WriteLine();
Console.WriteLine();
myList.RemoveElement(2);
for (int i = 0; i < myList.Elements.Length; i++)
{
Console.WriteLine(myList.Elements[i]);
}
Console.WriteLine();
myList.InsertElement(555, 0);
for (int i = 0; i < myList.Elements.Length; i++)
{
Console.WriteLine(myList.Elements[i]);
}
Console.WriteLine();
for (int i = 0; i < myList.Elements.Length; i++)
{
Console.WriteLine(myList.Elements[i]);
}
Console.WriteLine();
Console.WriteLine(myList.FindElement(555));
Console.WriteLine(myList.ToString());
Console.WriteLine();
Console.WriteLine(myList.GetElement(1));
}
示例8: GettingElementTest
public void GettingElementTest()
{
GenericList<string> generic = new GenericList<string>(2);
generic.AddElement("Pesho");
generic.AddElement("Gosho");
generic.AddElement("Kircho");
string element = generic.GetElement(0);
Assert.AreEqual("Pesho", element);
}