Hello,
I have two lists and need a list as result. Is there a way to solve this with LinQ?
If so, how?
My attempts, it would be better maybe to load it into a dictionary, but how?
HashSet<Tuple<string, bool>> hsResultList = new HashSet<Tuple<string, bool>>();
for (int side = 0; side <= 2; side++) // Side 1 and Side 2
{
foreach (var sB in CurrentPanel.ListSides[(int)side - 1].Boards )
{
var qryAlreadyInside = hsResultList.Where(x => x.Item1.Contains(sB.Index)).FirstOrDefault();
if ( qryAlreadyInside == null )
hsResultList.Add(new Tuple<string, bool>(sB.Index, sB.Badmark));
If the status is false in one list, the entire status must be false in the merged dictionary.
var dicSide1 = CurrentPanel.ListSides[0].ListSingleBoards.ToDictionary(x => x.Index, v => v.State);
var dicSide2 = CurrentPanel.ListSides[1].ListSingleBoards.ToDictionary(x => x.Index, v => v.State);
var dicResultSide1Side2Badmarks = dicSide1.Union(dicSide2.Where(k => !dicSide1.ContainsKey(k.Key))).ToDictionary(k => k.Key, v => v.Value);
int badBoards = dicResultSide1Side2Badmarks.Where(x => x.Value == false).Count();
int goodBoards = dicResultSide1Side2Badmarks.Where(x => x.Value == true).Count();
