using System.Collections.Generic;
public static void Main()
PatientDetails patient1 = new PatientDetails(){Name = "Venkat"};
PatientDetails patient2 = new PatientDetails(){Name = "Anusha"};
DoctorDetails doctor1 = new DoctorDetails(){Name = "Sai"};
DoctorDetails doctor2 = new DoctorDetails(){Name = "Siva"};
List<PatientDetails> lstPatients = new List<PatientDetails>(){patient1,patient2};
List<DoctorDetails> lstDoctors = new List<DoctorDetails>(){doctor1,doctor2};
Finder<PatientDetails> finder= new Finder<PatientDetails>();
Console.WriteLine(finder.Find(lstPatients,"Anusha"));
internal T Find(List<T> lst, string name)
var patient = x as PatientDetails;
return (T)Convert.ChangeType(patient, typeof(T));
var doctor = x as DoctorDetails;
return (T)Convert.ChangeType(doctor, typeof(T));
internal class PatientDetails
internal class DoctorDetails