本文整理汇总了C#中DynamicArray.InsertAt方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicArray.InsertAt方法的具体用法?C# DynamicArray.InsertAt怎么用?C# DynamicArray.InsertAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicArray
的用法示例。
在下文中一共展示了DynamicArray.InsertAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var array = new DynamicArray<string>();
array.Add("Georgi");
array.Add("Nikolai");
Console.WriteLine(array.IndexOf("Nikolai"));
Console.WriteLine(array.Cointains("Kiril"));
array.Remove("Georgi");
array.InsertAt(1, "Ivan");
array.Clear();
Console.WriteLine(array.Capacity);
Console.WriteLine(array.Count);
array.Add("Stefan");
array.Add("Krum");
var arr = array.ToArray();
Console.WriteLine();
foreach (var item in array)
{
Console.WriteLine(item);
}
Console.WriteLine();
foreach (var item in arr)
{
Console.WriteLine(item);
}
}
示例2: Main
public static void Main()
{
DynamicArray<string> arrey = new DynamicArray<string>();
arrey.Add("Pesho");
arrey.Add("Gosho");
Console.WriteLine(arrey.IndexOf("Pesho"));
Console.WriteLine(arrey.Contains("Gosho"));
Console.WriteLine(arrey.Contains("Ivan"));
arrey.Remove("Pesho");
arrey.InsertAt(1, "Pesho");
arrey.Clear();
Console.WriteLine(arrey.Capacity);
Console.WriteLine(arrey.Count);
arrey.Add("Ivo");
arrey[0] = "Gosho";
var newArrey = arrey.ToArray();
Console.WriteLine();
foreach (var item in arrey)
{
Console.WriteLine(item);
}
Console.WriteLine();
foreach (var item in newArrey)
{
Console.WriteLine(item);
}
}
示例3: Main
static void Main(string[] args)
{
Console.WriteLine("### LinkedList tests");
var list = new LinkedList<string>();
list.Add("x");
list.Add("g");
list.Add("s");
Console.WriteLine(list.Count); //output: 3
list.InsertAfter("g", "a");
list.InsertAt(10, "z");
list.InsertAt(2, "z");
list.Remove("z");
list[1] = "m";
foreach (string value in list)
{
Console.WriteLine(value);
}
//output:
//x
//m
//a
//s
Console.WriteLine("\n### DynamicArray tests");
var dArray = new DynamicArray<string>();
dArray.Add("x");
dArray.Add("g");
dArray.Add("s");
Console.WriteLine(dArray.Count); //output: 3
dArray.InsertAt(10, "z");
dArray.InsertAt(2, "z");
dArray.Remove("z");
dArray[1] = "m";
for (int i = 0; i < dArray.Count; i++)
{
Console.WriteLine(dArray[i]);
}
//output:
//x
//m
//a
//s
Console.WriteLine("\n### Map tests");
var map = new Map<int, string>();
map.Add(1, "a");
map.Add(2, "a");
map.Add(3, "s");
Console.WriteLine(map.Count); //output: 3
try
{
map.Add(2, "v");
}
catch (ArgumentException argEx)
{
Console.WriteLine(argEx.Message); //exception message
}
Console.WriteLine(map.ContainsKey(2)); //output: True
Console.WriteLine(map.ContainsValue("a")); //output: True
map.Remove(2);
Console.WriteLine(map.ContainsKey(2)); //output: False
Console.WriteLine(map.ContainsValue("a")); //output: True
Console.WriteLine(map.Count); //output: 2
Console.WriteLine("\n### HashMap tests");
var hashMap = new Map<int, string>();
hashMap.Add(1, "a");
hashMap.Add(2, "a");
hashMap.Add(3, "s");
Console.WriteLine(hashMap.Count); //output: 3
try
{
hashMap.Add(2, "v");
}
catch (ArgumentException argEx)
{
Console.WriteLine(argEx.Message); //exception message
}
Console.WriteLine(hashMap.ContainsKey(2)); //output: True
Console.WriteLine(hashMap.ContainsValue("a")); //output: True
hashMap.Remove(2);
//.........这里部分代码省略.........