本文整理汇总了C#中GenericList.GetIndexByValue方法的典型用法代码示例。如果您正苦于以下问题:C# GenericList.GetIndexByValue方法的具体用法?C# GenericList.GetIndexByValue怎么用?C# GenericList.GetIndexByValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericList
的用法示例。
在下文中一共展示了GenericList.GetIndexByValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
var list = new GenericList<int>();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(4);
list.Add(3);
Console.WriteLine(list);
list[4] = 5;
Console.WriteLine(list);
list.Add(-5);
Console.WriteLine(list);
Console.WriteLine("list[2] = " + list[2]);
Console.WriteLine();
list.RemoveByIndex(list.Count - 1);
Console.WriteLine(list);
Console.WriteLine();
list.Insert(list.Count, 0);
Console.WriteLine(list);
Console.WriteLine();
Console.WriteLine(list.GetIndexByValue(5));
Console.WriteLine(list.IsContain(5));
Console.WriteLine("Max = " + list.Max());
Console.WriteLine("Min = " + list.Min());
Console.WriteLine();
list.RemoveAll();
Console.WriteLine("Empty list" + list);
Type type = typeof(GenericList<>);
object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
Console.WriteLine("GenericsList's version is {0}", ((VersionAttribute)allAttributes[0]).Version);
}
示例2: Main
static void Main(string[] args)
{
var list = new GenericList<int>();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(4);
list.Add(5);
list[4] = 19;
Console.WriteLine(list);
list.Add(-5);
Console.WriteLine(list);
Console.WriteLine("list[4] = " + list[4]);
list.RemoveByIndex(list.Count - 1);
Console.WriteLine(list);
Console.WriteLine("{0}",new string('-',60));
list.Insert(list.Count, 5);
Console.WriteLine(list);
Console.WriteLine("{0}", new string('-', 60));
Console.WriteLine(list.GetIndexByValue(5));
Console.WriteLine(list.IsContain(8));
Console.WriteLine("{0}", new string('-', 60));
Console.WriteLine("Highest = " + list.Max());
Console.WriteLine("Lowest = " + list.Min());
Console.WriteLine("{0}", new string('-', 60));
list.RemoveAll();
Console.WriteLine("After the List was Deleted = " + list);
Console.WriteLine("{0}", new string('-', 60));
Type type = typeof(GenericList<>);
object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), true);
}
示例3: Main
public static void Main()
{
GenericList<int> newList = new GenericList<int>();
while (true)
{
Console.WriteLine("Enter number for adding to the Generic list OR \"end\":");
string input = Console.ReadLine();
if (input == "end")
{
break;
}
newList.ListAdd(int.Parse(input));
}
while (true)
{
Console.WriteLine("Enter index which value you want to get from the Generic list OR \"end\":");
string input = Console.ReadLine();
if (input == "end")
{
break;
}
int index = int.Parse(input);
Console.WriteLine("The element with index {0} in the Generic list is {1}.", index, newList.Access(index));
}
while (true)
{
Console.WriteLine("Enter index which value you want to remove from the Generic list OR \"end\":");
string input = Console.ReadLine();
if (input == "end")
{
break;
}
int index = int.Parse(input);
newList.Remove(index);
}
while (true)
{
Console.WriteLine("Enter index and value which you want to insert at the Generic list OR \"end\":");
Console.Write("Index: ");
string input = Console.ReadLine();
if (input == "end")
{
break;
}
int index = int.Parse(input);
Console.Write("Value:");
int value = int.Parse(Console.ReadLine());
newList.Insert(index, value);
}
Console.WriteLine("Do you want to clear the Generic list (\"Yes\" ot \"No\"):");
string answer = Console.ReadLine();
if (answer == "Yes")
{
newList.Clear();
Console.WriteLine("The array is cleared");
}
else
{
Console.WriteLine("The array is NOT cleared.");
}
while (true)
{
Console.WriteLine("Enter value which will be searched at the Generic list OR \"end\":");
string input = Console.ReadLine();
if (input == "end")
{
break;
}
int value = int.Parse(input);
Console.WriteLine("The value {0} has index {1} in the Generic list.", value, newList.GetIndexByValue(value));
}
if (newList.Length > 0)
{
Console.WriteLine("The maximal value in the Generic list is {0}", newList.Max<int>());
Console.WriteLine("The minimal value in the Generic list is {0}", newList.Min<int>());
}
else
{
Console.WriteLine("The generic list is empty.");
}
}