我試圖根據謂詞Func過濾列表。我使用Func過濾完整列表並返回操作的結果。然後我需要確定哪些MachineAction出現在完整列表中,但不是過濾列表。從另一個列表中刪除項目的擴展方法
static void Main(string[] args)
{
var allActions = new List<MachineAction>
{
new MachineAction
{ Name = "A", Status = MachineActionStatus.Cancelled },
new MachineAction
{ Name = "B", Status = MachineActionStatus.Error },
new MachineAction
{ Name = "C", Status = MachineActionStatus.Waiting }
};
var filteredActions = allActions.Where(FilterNotCompleted);
}
private readonly static Func<MachineAction, bool> FilterNotCompleted = action =>
(action.Status == MachineActionStatus.Waiting ||
action.Status == MachineActionStatus.Started);
public class MachineAction
{
public MachineActionStatus Status { get; internal set; }
public string Name { get; internal set; }
}
internal enum MachineActionStatus
{
Waiting,
Started,
Success,
Error,
Cancelled
} ;
是否有將完整名單與過濾列表,並返回那些未在這兩個擴展方法?
感謝