Using .Contains() on a property in a list

前端 未结 8 578
庸人自扰
庸人自扰 2020-12-10 18:01

I have a List of Activity. In the Activity class is an ID property (a Guid for arguments sake). I want to check if this list has an Activity in it with a Guid I have. Rather

8条回答
  •  既然无缘
    2020-12-10 18:20

    For those who can't use LINQ:

    List ActivityList = new List();
    
    foreach (Activity activity in ActivityList.FindAll(delegate(Activity a)
        {
            return a.Id == GuidToCompare;
        }))
    {
        //Code here
    }
    

提交回复
热议问题