0

I am searching for a method with searches through a List and returns an Index. It should find the first object witch member equals the string to search for.

I think there a several different methods implemented by default like "FindIndex".

What solution would you use to solve this Problem, or is a search function in a loop like the one Shown below a fast solution?

Here the Search Methode in MyClass searches through the list and looks for the first object with the member name equals str.

namespace MyNamespace
{
    class TestClass
    {
    //The name of the TestPerson
    public string name;
    //more members
    //.....
    }
}

namespace MyNamespace
{
    class MyClass
    {
        //Create List with 
        List<TestClass> testData = new List<TestClass>();

        //List filled with Data

        //Search for Index in testData with Personname matching str
        uint Search(string str)
        {
            for (int i = 0; i < Signals.Count; i++)
            {
                if (str == testData[i].name)
                {
                    return i;
                }
            }
        }
    }
}
Raros
  • 21
  • 1
  • 1
  • 7

0 Answers0