I want to search elements within a list:
public static string FindOne(string vehicleRego)
{
string vehicleDetails =
Fleet.vehicleList.Find(x => x.VehicleRego == vehicleRego).ToString();
return vehicleDetails;
}
But I'm not having any luck - I'm not sure how to get the whole 'row' and also how to just return one of the items in the object, say 'model'.
vehicleList is of type List<Vehicle> and Fleet.vehicleList.Find returns first match, so the return type is Vehicle
You could return the found Vehicle - this is the whole "row". If not found, null is returned.
public static Vehicle FindOneByRego(string vehicleRego)
{
return Fleet.vehicleList.Find(vehicle => vehicle.VehicleRego == vehicleRego);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With