Finding items in a list<of> C#

Many of you are asking how to perform searches on lists as detailed in the previous post using C# syntax. Well in a summary form this would be the equivalent expression:


Muchos de vosotros me estáis pidiendo como realizar búsquedas en listas como la detallada en el post anterior y en C#. Bien de una forma resumida esta sería la expresión equivalente :



public static List<Person> People = new List<Person> … // to do: Populate list




// Find name function
public static Person FindField(string toFind)
{
  Person result = People.Find(delegate(Person fl) {return fl.Name == toFind;});
  return result;
}


// ..
// ..
// ..
// Class Person
        public class Person
        {
            public string Name { get; set; }
            public string surname { get; set; }
            public int Age { get; set; }
        } 


I hope this will be useful,
Pep Lluis,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>