Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>When I hover over "join" I get "The type arguments for the method <code>IEnumerable System.Linq.Enumerable.Join(this Enumerable,IEnumerable, Func,Func....</code> cannot be infered from the query. </p> </blockquote> <p>I can explain what is going on here so that you can track it down.</p> <p>When you say</p> <pre><code>from firstitem in firstcollection join seconditem in secondcollection on firstkey equals secondkey select result </code></pre> <p>the compiler translates that into:</p> <pre><code>Enumerable.Join( firstcollection, secondcollection, firstitem=&gt;firstkey, seconditem=&gt;secondkey, (firstitem, seconditem)=&gt;result) </code></pre> <p><code>Enumerable.Join</code> is a generic method that has four type parameters: the element type of the first collection, the element type of the second collection, the key type, and the result type.</p> <p>If you're getting that error then one of those four things cannot be deduced given the information you've provided to the compiler. For example, maybe:</p> <ul> <li>The type of the first collection is not actually a sequence.</li> <li>The type of the second collection is not actually a sequence.</li> <li>The type of the result cannot be deduced</li> <li>The two keys are of inconsistent types and there is no unique best type.</li> </ul> <p>That last point is the most likely one. Suppose for example the first key is <code>int</code> and the second key is <code>short</code>. Since every <code>short</code> can be converted to <code>int</code>, <code>int</code> would win, and the second key would be automatically converted to <code>int</code>. Now suppose that the first key type is <code>Giraffe</code> and the second key type is <code>Tiger</code>. Neither is better than the other. C# does not say "oh, they're both kinds of <code>Animal</code>, so let's pick that." Rather, it says that you haven't provided enough information to determine which one you meant; you should cast one of them to <code>Animal</code> and then it becomes clear.</p> <p>Make sense?</p> <p>There's a half-hour video of me explaining this feature back in 2006 -- this was back when I was adding the feature in question to the compiler -- so if you want a more in-depth explanation, check it out.</p> <p><a href="http://ericlippert.com/2006/11/17/a-face-made-for-email-part-three/" rel="noreferrer">http://ericlippert.com/2006/11/17/a-face-made-for-email-part-three/</a></p> <p>UPDATE: I just read your question again more carefully:</p> <blockquote> <p>Part of the problem as that I'm trying to compare/join an <code>ArrayList</code> and an <code>IGenericListItem</code>.</p> </blockquote> <p>There's the problem. The type of the sequence cannot be determined from an <code>ArrayList</code>. You should not use <code>ArrayList</code> anymore. In fact, you should not use it in any code written after 2005. Use <code>List&lt;T&gt;</code> for some suitable T.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload