本文整理汇总了C#中GenericList.FindIndex方法的典型用法代码示例。如果您正苦于以下问题:C# GenericList.FindIndex方法的具体用法?C# GenericList.FindIndex怎么用?C# GenericList.FindIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericList
的用法示例。
在下文中一共展示了GenericList.FindIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
GenericList<string> myList = new GenericList<string>();
Console.WriteLine(myList.Capacity);
Console.WriteLine(myList.Count);
Console.WriteLine(myList.Elements);
myList.Add("1");
myList.Add("2");
myList.Add("3");
myList.Add("4");
myList.Add("Gosho");
myList.RemoveAt(3);
Console.WriteLine(myList.Capacity);
Console.WriteLine(myList.Count);
Console.WriteLine(myList.Elements);
myList.InsertAt(0, "Viki");
Console.WriteLine(myList.FindIndex("Viki"));
Console.WriteLine(myList.FindIndex("1"));
myList.InsertAt(0, "Viki");
myList.InsertAt(5, "Viktor");
myList.InsertAt(7, "Viktor");
myList.Clear();
myList.Add("Pesho");
}
示例2: Main
static void Main(string[] args)
{
GenericList<string> genericList = new GenericList<string>();
genericList.Add("a");
genericList.Add("b");
genericList.Add("c");
Console.WriteLine(genericList);
Console.WriteLine("Max = {0}, Min = {1}",genericList.Max(),genericList.Min());
Console.WriteLine("Remove b");
genericList.Remove("b");
Console.WriteLine(genericList);
Console.WriteLine("genericList[0] = "+genericList.Access(0));
Console.WriteLine("index of c = "+genericList.FindIndex("c"));
genericList.Clear();
genericList.Add("rom");
genericList.Add("mon");
genericList.Add("dom");
Console.WriteLine(genericList);
Console.WriteLine("Insert zom (index = 1)");
genericList.Insert("zom",1);
Console.WriteLine(genericList);
Console.WriteLine(genericList.Contains("mon"));
Console.WriteLine(genericList.Contains("aaa"));
Type type = typeof(GenericList<>);
object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
foreach (VersionAttribute attr in allAttributes)
{
Console.WriteLine("This class's version is {0}.", attr.Version);
}
}
示例3: Main
static void Main()
{
GenericList<int> nums = new GenericList<int>(2);
// Add elements
nums.AddElement(5);
nums.AddElement(10);
nums.AddElement(1);
nums.AddElement(8);
Console.WriteLine("List after adding elements: " + nums + "\n");
// Remove elements
nums.RemoveElement(1);
nums.RemoveElement(2);
Console.WriteLine("List after removing elements: " + nums + "\n");
// show element at index
Console.WriteLine("Element at given index: " + nums.ElementAtIndex(0) + "\n");
// insert elements at index
nums.InsertElementAtIndex(10, 50);
Console.WriteLine(nums);
nums.InsertElementAtIndex(1, 999);
Console.WriteLine(nums + "\n");
// find index of given element
nums.FindIndex(999);
nums.FindIndex(444);
Console.WriteLine();
// check if list contains element
Console.WriteLine(nums.Contains(999));
Console.WriteLine(nums.Contains(444));
Console.WriteLine();
// find min element
Console.WriteLine("Min element is: " + GenericList<int>.Min(10, 7) + "\n");
// find max element
Console.WriteLine("Max element is: " + GenericList<string>.Max("Albena", "Ruse"));
// clear list
nums.ClearList();
Console.WriteLine(nums);
}
示例4: Main
public static void Main()
{
//Test for strings
Console.WriteLine("Enter capacity for the list of strings");
long capacity = long.Parse(Console.ReadLine());
GenericList<string> listStrings = new GenericList<string>(capacity);
listStrings.Add("Gosho"); //0
listStrings.Add("Pesho"); //1
listStrings.Add("Ivan"); //2
listStrings.Add("Andrei"); //3
listStrings.Add("Niki"); //4
listStrings.Add("Svetlin"); //5
Console.WriteLine(listStrings.ToString()); //Printing the list
//Remove the element at position 0 and then move the list
//Do the same with with 2 and then add to the position 3 a new string
listStrings.Remove(0);
listStrings.Remove(2);
listStrings[3] = "Doncho";
Console.WriteLine(listStrings.ToString()); //Printing the list
string key = "Svetlin";
Console.WriteLine("The string '{0}' is on position {1} on the list ", key, listStrings.FindIndex(key));
Console.WriteLine("The min value is {0}", listStrings.Min());
Console.WriteLine("The max value is {0}", listStrings.Max());
listStrings.Clear();
Console.WriteLine(listStrings.ToString()); //Printing the list
Console.WriteLine();
//Test with doubles
Console.WriteLine("Enter capacity for the list of doubles");
capacity = long.Parse(Console.ReadLine());
GenericList<double> listDoubles = new GenericList<double>(capacity);
listDoubles.Add(5.632); //0
listDoubles.Add(123.45); //1
listDoubles.Add(-34.213);//2
listDoubles.Add(43.1); //3
listDoubles.Add(4.1); //4
listDoubles.Add(3.1415); //5
listDoubles.Add(2.71); //6
Console.WriteLine(listDoubles.ToString()); //Printing the list
//Remove the element at position 0 and then move the list
//Do the same with with 3 and then add to the position 3 a new string
listDoubles.Remove(1);
listDoubles.Remove(3);
listDoubles[4] = 5.1;
Console.WriteLine(listDoubles.ToString()); //Printing the list
double key2 = 3.1415;
Console.WriteLine("The string '{0}' is on position {1} on the list ", key2, listDoubles.FindIndex(key2));
Console.WriteLine("The min value is {0}", listDoubles.Min());
Console.WriteLine("The max value is {0}", listDoubles.Max());
listDoubles.Clear();
Console.WriteLine(listDoubles.ToString()); //Printing the list
}
示例5: Main
private static void Main()
{
//01-GalacticGPS
var home = new Location(18.037986, 28.870097, Planet.Earth);
Console.WriteLine(home);
//02-FractionCalculator
var fraction1 = new Fraction(22, 7);
var fraction2 = new Fraction(40, 4);
var result = fraction1 + fraction2;
Console.WriteLine(result.Numerator);
Console.WriteLine(result.Denominator);
Console.WriteLine(result);
//03-GenericList
var list = new GenericList<int>();
list.Add(5);
Console.WriteLine(list[0]);
list.Add(1);
list.Add(2);
list.Add(3);
list.Remove(1);
Console.WriteLine(list[1]);
var newList = new GenericList<int>();
for (var i = 0; i < 5000; i++)
{
newList.Add(i);
//Console.WriteLine(newList[i]);
}
//newList.Clear();
//Console.WriteLine(newList[1]);
var id = newList.FindIndex(8);
Console.WriteLine("Id found: " + id);
Console.WriteLine(newList);
newList.GetAttribute();
}
示例6: Main
static void Main()
{
GenericList<int> genericList = new GenericList<int>();
genericList.Add(4);
genericList.Add(5);
genericList.Add(6);
genericList.Add(7);
genericList.Add(8);
Console.WriteLine(genericList);
genericList.Remove(3);
Console.WriteLine(genericList);
genericList.Remove(0);
Console.WriteLine(genericList);
Console.WriteLine("Containt 5: {0}", genericList.Contains(5));
Console.WriteLine("Containt 7: {0}", genericList.Contains(7));
Console.WriteLine("Index 0 value: {0}", genericList.Access(0));
Console.WriteLine("Index of 8 is {0}", genericList.FindIndex(8));
genericList.Insert(0, 16);
Console.WriteLine(genericList);
Console.WriteLine("Min: {0}", genericList.Min());
Console.WriteLine("Max: {0}", genericList.Max());
Console.WriteLine();
GenericList<string> genericStringList = new GenericList<string>();
genericStringList.Add("az");
genericStringList.Add("ti");
genericStringList.Add("tq");
genericStringList.Add("toi");
genericStringList.Add("to");
Console.WriteLine(genericStringList);
genericStringList.Remove(3);
Console.WriteLine(genericStringList);
genericStringList.Remove(0);
Console.WriteLine(genericStringList);
Console.WriteLine("Containt \"ti\": {0}", genericStringList.Contains("ti"));
Console.WriteLine("Containt Pesho: {0}", genericStringList.Contains("Pesho"));
Console.WriteLine("Index 0 value: {0}", genericStringList.Access(0));
Console.WriteLine("Index of \"to\" is {0}",genericStringList.FindIndex("to"));
genericStringList.Insert(0, "Gosho");
Console.WriteLine(genericStringList);
Console.WriteLine("Min: {0}", genericStringList.Min());
Console.WriteLine("Max: {0}", genericStringList.Max());
}
示例7: Main
static void Main()
{
GenericList<string> myList = new GenericList<string>();
Console.WriteLine("Assigning value of \"ajh\" to the elements");
for (int i = 0; i < 15; i++)
{
myList.Add("ajh");
}
Console.WriteLine(" Overriden ToString method :\n {0}\n", myList);
myList[2] = "bef";
Console.WriteLine(" Change value on index [2] to \"bef\"\n{0}\n", myList);
Console.WriteLine("Use FindIndex method for \"bef\" value :\n {0}\n", myList.FindIndex("bef"));
string min = myList.FindMin();
Console.WriteLine("Using FindMin : {0}", min);
string max = myList.FindMax();
Console.WriteLine("Using FindMax : {0}\n", max);
Console.WriteLine("Using Contains(\"j\") : {0}", myList.Contains("j"));
Console.WriteLine("Using Contains(\"bef\") : {0}\n", myList.Contains("bef"));
myList.Remove(2);
Console.WriteLine("Use Remove method for index [2] :\n {0}\n", myList);
myList.Clear();
Console.WriteLine("Using Clear method : \n {0}\n", myList);
Type info = typeof(GenericList<>);
object[] myVersion = info.GetCustomAttributes(false);
for (int i = 0; i < myVersion.Length; i++)
{
if (i == 0)
{
Console.WriteLine("Version : {0}", (Attribute)myVersion[i]);
}
}
}
示例8: Main
public static void Main()
{
var list = new GenericList<int> { 2, 3, 4, 5, 6, 7, 8, 9, 10 };
list.Version();
Console.WriteLine(list.Count);
list.Add(1);
Console.WriteLine(list.Count);
Console.WriteLine(list.Min());
Console.WriteLine(list.Max());
Console.WriteLine(list.Contains(11));
Console.WriteLine(list.FindIndex(3));
list.Insert(0, 5);
Console.WriteLine(list);
list.Remove(0);
Console.WriteLine(list);
list[0] = 18;
Console.WriteLine(list);
list.Clear();
Console.WriteLine(list);
}
示例9: Main
static void Main(string[] args)
{
var list = new GenericList<int>{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
list.Version();
Console.WriteLine(list.Count);
list.Add(1);
Console.WriteLine(list.Count);
Console.WriteLine(list.Min());
Console.WriteLine(list.Max());
Console.WriteLine(list.Contains(6));
Console.WriteLine(list.FindIndex(17));
list.Insert(21341, 12);
Console.WriteLine(list);
list.Remove(0);
Console.WriteLine(list);
list[2] = 23;
Console.WriteLine(list);
list.Clear();
Console.WriteLine(list);
}
示例10: Main
static void Main()
{
object[] versionAttributes = typeof(GenericList<int>).GetCustomAttributes(false);
foreach (var attribute in versionAttributes)
{
Console.WriteLine("The Version of the class is: {0}", attribute);
}
try
{
var list = new GenericList<int>();
for (int i = 0; i < 20; i++)
{
list.Add(i);
}
list.Insert(3, 22);
list.Add(100);
list.Add(-4);
list.Add(102);
list.RemoveAt(5);
Console.WriteLine(list);
int index = list.FindIndex(22);
Console.WriteLine(list.Contains(10));
Console.WriteLine(index);
Console.WriteLine("Max: {0}", list.Max());
Console.WriteLine("Min: {0}", list.Min());
list.Clear();
for (int i = 0; i < 100; i += 2)
{
list.Add(i);
}
Console.WriteLine(list);
}
catch (ArgumentOutOfRangeException ex)
{
Console.WriteLine(ex.Message);
}
}
示例11: Main
static void Main(string[] args)
{
//Problem 3 and 4 Solution
var list = new GenericList<int> { 2, 3, 4, 5, 6, 7, 8, 9, 10 };
list.Version();
Console.WriteLine(list.Count);
list.Add(1);
Console.WriteLine(list.Count);
Console.WriteLine(list.Min());
Console.WriteLine(list.Max());
Console.WriteLine(list.Contains(11));
Console.WriteLine(list.FindIndex(3));
list.Insert(0, 5);
Console.WriteLine(list);
list.Remove(0);
Console.WriteLine(list);
list[0] = 18;
Console.WriteLine(list);
list.Clear();
Console.WriteLine(list);
}
示例12: Main
static void Main()
{
GenericList<double> list1 = new GenericList<double>(4);
list1.Add(1);
list1.Add(2);
list1.Add(3);
list1.Add(4);
list1.Add(5);
Console.WriteLine(list1);
list1.RemoveAt(2);
Console.WriteLine(list1);
list1.Insert(0, 20);
list1.Insert(5, 100);
Console.WriteLine(list1);
int value = 5;
int pos = list1.FindIndex(i => i == value);
Console.WriteLine("{0} is at index {1}", value, pos);
// using the member methods
double min1 = list1.Min();
Console.WriteLine("Min: {0}", min1);
double max1 = list1.Max();
Console.WriteLine("Max: {0}", max1);
}
示例13: Main
static void Main()
{
// Task 5, 6
GenericList<int> gl = new GenericList<int>();
gl.Add(4);
gl.Add(3);
gl.Add(2);
gl.Add(2);
Console.WriteLine(gl);
gl.Add(5);
Console.WriteLine(gl);
Console.WriteLine(gl.FindIndex(2));
gl.RemoveAt(1);
Console.WriteLine(gl);
gl.InsertAt(15, 2);
Console.WriteLine(gl);
// Task 7
Console.WriteLine(gl.Min());
Console.WriteLine(gl.Max());
}
示例14: Main
static void Main(string[] args)
{
var list = new GenericList<int>();
list.addElement(60);
list.addElement(6);
list.addElement(12);
list.addElement(9756);
list.addElement(3);
list.addElement(74);
list.addElement(687);
list.addElement(123);
list.Version();
Console.WriteLine();
Console.WriteLine("Start list --> {0}\n", list);
Console.WriteLine("Max: ---> {0}\n", list.Max());
Console.WriteLine("Min: ---> {0}\n", list.Min());
list.Insert(7, 2);
list.Insert(300, 1);
Console.WriteLine("Insert: 300 and 7 ---> {0}\n", list);
Console.WriteLine("Accessed by index 3 --> {0}\n", list.Access(3));
Console.WriteLine(list.Contains(74));
Console.WriteLine(list.Contains(4));
Console.WriteLine();
list.removeElement(4);
list.removeElement(6);
Console.WriteLine("After removal ---> {0}\n", list);
Console.WriteLine("Found indexes:");
Console.WriteLine("Index of 1 --> {0}", list.FindIndex(1));
Console.WriteLine("Index of 60 --> {0}\n", list.FindIndex(60));
Console.WriteLine("Final list --> {0}\n", list);
// list = new GenericList<int>();
list.Clear();
Console.WriteLine("Cleared --> {0}\n", list);
list.addElement(60);
list.addElement(6);
list.addElement(12);
list.addElement(9756);
list.addElement(3);
list.addElement(74);
list.addElement(687);
list.addElement(123);
list.addElement(60);
list.addElement(6);
list.addElement(12);
list.addElement(9756);
list.addElement(3);
list.addElement(74);
list.addElement(687);
list.addElement(123);
list.addElement(60);
list.addElement(6);
list.addElement(12);
list.addElement(9756);
list.addElement(3);
list.addElement(74);
list.addElement(687);
list.addElement(123);
Console.WriteLine("List with more than 16 symbols --> {0}", list);
}
示例15: TestFindIndex
public void TestFindIndex()
{
GenericList<int> numbers = new GenericList<int>();
numbers.Add(1);
numbers.Add(2);
numbers.Add(3);
numbers.Add(4);
numbers.Add(5);
int value = 5;
int pos = numbers.FindIndex(n => n == value);
Assert.AreEqual(4, pos);
}