我有一个名为OfferPriorities的对象列表,OfferPriority有一个字段TypeId。我想确保OfferPriorities中存在所有TypeId值。可能的TypeId值是1,2和3.我想检查OfferPriorities中是否存在所有这些值。例如,下面TypeId 3在列表中不存在,所以我应该抛出异常。
答案 0 :(得分:3)
<TextView
android:id="@+id/myTextView"
... (rest of lines)
app:layout_constraintVertical_bias="0.22000003" />
+ Except
做你想做的事:
Any
答案 1 :(得分:0)
另一种可能是使用All
来检查OfferPriorities
是否包含所有元素:
List<OfferPriority> OfferPriorities = new List<OfferPriority>();
OfferPriorities.Add(new OfferPriority() { TypeId = 1 });
OfferPriorities.Add(new OfferPriority() { TypeId = 2 });
//OfferPriorities.Add(new OfferPriority() { TypeId = 3 });
List<int> allowedIDs = new List<int> { 1, 2, 3 };
bool check = allowedIDs.All(x => OfferPriorities.Select(y => y.TypeId).Contains(x));