title: Looking for LINQ expression for foreach loop
body: <p>I have 2 device classes,</p>
  
  <pre><code>public class Device1
  {
      public string DeviceName { get; set; }
      public string IP { get; set; }
      public bool IsExist { get; set; }
  }
  public class Device2
  {
      public string DeviceName { get; set; }
      public string DeviceIP { get; set; }
  }
  </code></pre>
  
  <p>The current value for "IsExist" is "false" for "Device1[]" array,</p>
  
  <pre><code>private static Device1[] GetDevice1Arr()
      {
          List&lt;Device1&gt; d1List = new List&lt;Device1&gt;() {
              new Device1 { DeviceName="d1", IP="1", IsExist=false},
              new Device1 { DeviceName="d2", IP="1", IsExist=false}
          };
  
          return d1List.ToArray();
      }
  </code></pre>
  
  <p>Now "Device2[]" array don't having "IsExist",</p>
  
  <pre><code> private static Device2[] GetDevice2Arr()
      {
          List&lt;Device2&gt; d2List = new List&lt;Device2&gt;() {
              new Device2 { DeviceName="d1", DeviceIP="3"},
              new Device2 { DeviceName="d2", DeviceIP="1"},
              new Device2 { DeviceName="d2", DeviceIP="2"},
              new Device2 { DeviceName="d3", DeviceIP="3"}
          };
  
          return d2List.ToArray();
      }
  </code></pre>
  
  <p>Now I am comparing both array "Device1[]" and "Device2[]" by using 2 "foreach" loop, if DeviceName and DeviceIP is same, I am resetting "IsExist" = "true".</p>
  
  <p><strong>Looking for LINQ replacement here or any alternate way</strong>. Thanks!</p>
  
  <pre><code>Device1[] d1 = GetDevice1Arr();
  Device2[] d2 = GetDevice2Arr();
  
  foreach(var device1 in d1)
  {
      foreach(var device2 in d2)
      {
          if(device2.DeviceName == device1.DeviceName &amp;&amp; device2.DeviceIP == device1.IP)
          {
              device1.IsExist = true;
          }
      }
  }
  </code></pre>