title: Comparing a list of values against the property of an object (list) using LINQ
body: <p>I am having trouble comparing two lists using Linq.<br />
  My first list contains object instances, which contain a property of interest, to be compared against a second list that contains only values.<br />
  Say we have:</p>
  <pre><code>List&lt;uint&gt; referenceValues = new List&lt;uint&gt;(){1, 2, 3};
  and
  List&lt;SomeObject&gt; myObject= new List&lt;SomeObject&gt;();
  </code></pre>
  <p>Now the SomeObject() class has the property &quot;Value&quot; of type uint.<br />
  Note that &quot;myObject&quot; list may contains more elements than the &quot;referenceValues&quot; list and we therefore have to select the appropriate portion of &quot;myObject&quot; to be compared against &quot;referenceValues&quot;.</p>
  <p>I have found the following stack overflow question, which is related, but not quite what I am after: <a href="https://stackoverflow.com/questions/33553373/compare-list-of-strings-with-object-properties-in-another-list">link</a></p>
  <p>Here is what I have tried so far, but without success:</p>
  <pre><code>if (myObject
      .GetRange((int)offset, count)       // Extracted the object of interest from the list
      .Where(x =&gt; referenceValues.Equals(x.Value)).Count() == 0)   // Comparing the &quot;Value&quot; properties against the &quot;referenceValues&quot;
  {
      // Do something
  }
  </code></pre>
  <p>I think I need to use &quot;SequenceEqual&quot; somehow, but I am not really getting how to.<br />
  Any advice would be very welcome.</p>
  <h2>EDIT</h2>
  <p>Reproducible example:</p>
  <pre><code>using System;
  using System.Linq;
  using System.Collections.Generic;
                      
  public class Program
  {
      public static void Main()
      {
          int offset = 0;
              
          List&lt;uint&gt; referenceValues = new List&lt;uint&gt;(){1, 2, 3};
  
          List&lt;SomeObject&gt; myObject= new List&lt;SomeObject&gt;(){new SomeObject(){Value=1}, 
                                                            new SomeObject(){Value=2},
                                                            new SomeObject(){Value=3}};
          
          if (myObject
              .GetRange(offset, referenceValues.Count()-1)       // Extracted the object of interest from the list
              .Where(x =&gt; referenceValues.Equals(x.Value)).Count() == referenceValues.Count())   // Comparing the &quot;Value&quot; properties against the &quot;referenceValues&quot;
          {
              // Do something
              Console.WriteLine(&quot;Lists are matching!&quot;);
          }
          else
          {
              Console.WriteLine(&quot;Lists are not matching!&quot;);
          }
      }
  }
  
  public class SomeObject
  {
      public uint Value = 0;
  }
  </code></pre>
  <h2>EDIT2</h2>
  <p>Working solution as per suggestion from Guru Stron:</p>
  <pre><code>using System;
  using System.Linq;
  using System.Collections.Generic;
                      
  public class Program
  {
      public static void Main()
      {
          int offset = 0;
              
          List&lt;uint&gt; referenceValues = new List&lt;uint&gt;(){1, 2, 3};
  
          List&lt;SomeObject&gt; myObject= new List&lt;SomeObject&gt;(){new SomeObject(){Value=1}, 
                                                            new SomeObject(){Value=2},
                                                            new SomeObject(){Value=3}};
          
          if (myObject.
              GetRange((int)offset, referenceValues.Count())   
              .Select(someObject =&gt; someObject.Value)
              .SequenceEqual(referenceValues))
          {
              // Do something
              Console.WriteLine(&quot;Lists are matching!&quot;);
          }
          else
          {
              Console.WriteLine(&quot;Lists are not matching!&quot;);
          }
      }
  }
  
  public class SomeObject
  {
      public uint Value = 0;
  }
  </code></pre>
  <p>Recommended book about Linq expressions: LINQ Pocket Reference</p>