Firstly, my situation is here ...
- My SomeObject has a property
string Statusthat interests me for this scenario. - The Status property can contain the values "Open", "Closed", "Finish".
- I have a method called
FilterObjectsthat returnsList<SomeObject> - The method takes an argument in the same way as its return type,
List<SomeObject> - The method is supposed to be filtered in accordance with the following cases described below and return a list of objects.
List<SomeObject> I send as an argument to my method, it will be guaranteed to be in order (through their identifier and type).
Cases (all related to the property string Statusthat I mentioned):
- If any element in the list contains
Status = "Finished";, then eliminate all other elements that were in the original list, and return only the object with the status "Finished". If any element does NOT contain Status = Finished, but contains "CLOSED", I need to check if there is any other element that has the value "Open" after that, "CLOSED" is "one. You can think of it as a" task, which can be closed, but can be reopened, but once it is finished, it cannot be opened. "
"" "" , . "" , - , .
MS Paint.

, :
private List<SomeObject> FilterObjects(List<SomeObject> objectList)
{
var objects = objectList;
var returnList = new List<SomeObject>();
foreach (var obj in objects)
{
if (obj.Status == "Finished")
{
returnList.Add(obj);
return returnList;
}
}
return new List<SomeObject>();
}
, ? , , , , FINISHED. LINQ-?
, , , , .
.