Count() a specfic attribute within a list c#

前端 未结 3 1069
一向
一向 2021-01-28 17:32
if (gardenvlist.Count() == getava.Count())
{

}
else if(oceanvlist.Count() == getava.Count())
{

}
else if (cityvlist.Count() == getava.Count())
{

}

<

3条回答
  •  误落风尘
    2021-01-28 17:46

    If I understand your question correctly, you can pass in a lambda expression to Count() to selectively count items based on properties then compare that to whatever you'd like. Something like this:

    if (gardenvlist.Count()== getava.Count(x => x.Name == "GardenName"))

    Note you will need to add the following using statement: using System.Linq

提交回复
热议问题