本文整理汇总了C#中GenericList.InsertAtPosition方法的典型用法代码示例。如果您正苦于以下问题:C# GenericList.InsertAtPosition方法的具体用法?C# GenericList.InsertAtPosition怎么用?C# GenericList.InsertAtPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericList
的用法示例。
在下文中一共展示了GenericList.InsertAtPosition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
{
//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()
{
// 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();
}
示例4: 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);
}
}
示例5: Main
static void Main(string[] args)
{
GenericList<int> testList = new GenericList<int>(5);
testList.AddElement(55);
testList.AddElement(550);
testList.AddElement(-55);
testList.AddElement(564565);
testList.AddElement(-568);
testList.AddElement(5500);
testList.AddElement(5858645);
testList.AddElement(4444);
Console.WriteLine(testList.SearchByValue(-568));
Console.WriteLine(testList.ReadElement(1));
testList.RemoveElement(1);
testList.InsertAtPosition(2, -696969);
Console.WriteLine(testList.Max());
Console.WriteLine(testList.Min());
}
示例6: Main
static void Main()
{
GenericList<Test> list = new GenericList<Test>(10);
for (int i = 0; i < list.Length; i++)
{
Test testObject = new Test();
testObject.Id = i;
testObject.Content = "Some text " + i;
list.Add(testObject);
}
Console.WriteLine("Element at position 3, content: {0}", list[3].Content);
list.RemoveAtPosition(3);
Console.WriteLine("Element at position 3 after Remove, content: {0}", list[3].Content);
list.InsertAtPosition(3, new Test() { Id = 3, Content = "Some text 3" });
Console.WriteLine("Element at position 3 after Insert, content: {0}", list[3].Content);
}
示例7: Main
static void Main()
{
int size = 5;
GenericList<int> integerNum = new GenericList<int>(size);
//adding element
for (int i = 0; i < integerNum.ArraySize; i++)
{
integerNum.Add(i + 5);
}
//add size + 1 element to generate error
//integerNum.Add(135);
//removing element by index
integerNum.DeleteByIndex(1);
Console.WriteLine(integerNum.ToString());
//insert element
integerNum.InsertAtPosition(7, 59999);
Console.WriteLine(integerNum.ToString());
//clear
integerNum.Clear();
Console.WriteLine(integerNum.ToString());
integerNum.Add(78);
//finding element by its value
integerNum.Add(78);
integerNum.Add(15);
integerNum.Add(450);
Console.WriteLine(integerNum.FindElementByValue(6));
Console.WriteLine(integerNum.FindElementByValue(78));
//ToString()
Console.WriteLine(integerNum.ToString());
}