Using .Contains() on a property in a list

前端 未结 8 589
庸人自扰
庸人自扰 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:12

    I Havent tested it but im fairly sure this should work:

    if ( ActivityList.Any ( a => a.Id == GuidToCompare ) ) {
        // TODO - Exists.
    }
    

    MSDN Any : http://msdn.microsoft.com/en-us/library/bb534972.aspx

提交回复
热议问题