using System.Collections.Generic;
using System.Threading.Tasks;
static void Main(string[] args)
List<Patient> lstPatient = new List<Patient>();
lstPatient.Add(new Patient { Id = 1, Name = "Patient 1", Age = 23 });
lstPatient.Add(new Patient { Id = 2, Name = "Patient 2", Age = 24 });
lstPatient.Add(new Patient { Id = 3, Name = "Patient 3", Age = 25 });
List<Doctor> lstDoctor = new List<Doctor>();
lstDoctor.Add(new Doctor { Id = 1, Name = "Doctor 1", Age = 23 });
lstDoctor.Add(new Doctor { Id = 2, Name = "Doctor 2", Age = 24 });
lstDoctor.Add(new Doctor { Id = 3, Name = "Patient 1", Age = 23 });
List<Patient> rstPatient = Search.LikeSearch<Patient>(lstPatient,"Name", "Patient 2");
List<Doctor> rstDoctor = Search.LikeSearch<Doctor>(lstDoctor, "Name", "Doctor 4");
if(rstPatient!=null && rstPatient.Count>0)
Console.WriteLine("Patient Details");
Console.WriteLine("Id\t\t\t Name\t\t\t Age");
Console.WriteLine("===\t\t\t ======\t\t\t =====");
rstPatient.ForEach(d => {
Console.WriteLine(d.Id+"\t\t\t"+ d.Name+"\t\t"+d.Age);});
Console.WriteLine("Nothing Found");
Console.WriteLine("\n\n");
Console.WriteLine("Doctors Details");
if (rstDoctor != null && rstDoctor.Count > 0)
Console.WriteLine("Id\t\t\t Name\t\t\t Age");
Console.WriteLine("===\t\t\t ======\t\t\t =====");
Console.WriteLine(d.Id + "\t\t\t" + d.Name + "\t\t" + d.Age);
Console.WriteLine("Nothing Found");
public static class Search
public static List<T> LikeSearch<T>(this List<T> data, string key, string searchString)
var property = typeof(T).GetProperty(key, BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Instance);
throw new ArgumentException($"'{typeof(T).Name}' does not implement a public get property named '{key}'.");
object o = property.GetValue(data[0]);
return data.Where(d => property.GetValue(d).Equals(searchString)).ToList();
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }