I have been trying to implement the below foreach to linq , but couldn't get my head around doing it. Can anyone give me pointers on how I can go about changing this to linq or in general on how to think in terms of linq rather than using for loops.
class Program
{
static void Main(string[] args)
{
List<Sales> S1 = new List<Sales>();
S1.Add(new Sales(1,1,false));
S1.Add(new Sales(1, 1, false));
S1.Add(new Sales(2, 2, false));
S1.Add(new Sales(3, 3, false));
S1.Add(new Sales(4, 4, false));
List<Sales> S2 = new List<Sales>();
S2.Add(new Sales(3, 3, false));
S2.Add(new Sales(4, 4, false));
//if S1 Product1 == S2 Product1 and S1 Product2 == S2 Product2 then S1 isSold == true.
for(int i = 0; i < S2.Count; i++)
{
for(int j = 0; j < S1.Count; j++)
{
if(S1[j].Product1 == S2[i].Product1 && S1[j].Product2 == S2[i].Product2)
{
S1[j].ISSold = true;
}
}
}
}
public class Sales
{
public int Product1 { get; set; }
public int Product2 { get; set; }
public bool ISSold { get; set; }
public Sales(int product1, int product2, bool iSSold)
{
Product1 = product1;
Product2 = product2;
ISSold = iSSold;
}
}
}
}