You can also consider this method, merge them, and then group them to determine whether there is false in each group:
public static void Main()
{
List<A> list1 = new List<A>() {
new A(){ Index = 1, State = false },
new A(){ Index = 2, State = false },
new A(){ Index = 3, State = true },
new A(){ Index = 4, State = false },
new A(){ Index = 5, State = false },
};
List<A> list2 = new List<A>() {
new A(){ Index = 1, State = false },
new A(){ Index = 2, State = true },
new A(){ Index = 3, State = true },
new A(){ Index = 4, State = false },
new A(){ Index = 5, State = false },
new A(){ Index = 6, State = true },
new A(){ Index = 7, State = false },
};
var list = list1.Concat(list2);
var re = from a in list
group a by a.Index into g
select new
{
Key = g.Key,
Value = g.Where(x => x.State == false).Count() > 0 ? false : true
};
Dictionary<int, bool> dict1 = re.ToDictionary(x => x.Key, y => y.Value);
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.