Reputation: 560
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'.
Upvotes: 3
Views: 74
Reputation: 2142
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);
}
Upvotes: 3