Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need <code>Option Infer On</code> and then just use the <code>Dim</code> keyword, thus:</p> <pre><code>Dim query = From x In y Where x.z = w Select x </code></pre> <p>Contrary to some of the other answers, you <em>do not</em> need <code>Option Strict On</code>.</p> <p>If you're using the VS IDE you can just hover over the variable names, but to get the compile-time types of variables (<code>GetType(variableName)</code> does not compile - "Type '&lt;variablename&gt;' is not defined." - and <code>VarType(variable)</code> is actually just the VB version of <code>variable.GetType()</code> which returns the type of the instance stored in the variable at runtime) I used:</p> <pre><code>Function MyVarType(Of T)(ByRef Var As T) As Type Return GetType(T) End Function </code></pre> <p>In detail:</p> <ul> <li><p>without <code>Dim</code>:</p> <p><code>Explicit Off</code>, gives <code>Object</code></p> <p><code>Explicit On</code>, error "Name '' is not declared."</p></li> <li><p>with <code>Dim</code>:</p> <ul> <li><code>Infer On</code>, gives expected types</li> <li><p><code>Infer Off</code>:</p> <p><code>Strict On</code>, error "Option Strict On requires all declarations to have an 'As' clasue."</p> <p><code>Strict Off</code>, gives <code>Object</code></p></li> </ul></li> </ul> <p>As I mentioned in the comments, there are <a href="https://github.com/dotnet/roslyn/issues/10457" rel="noreferrer">other reasons</a> why <code>Option Strict On</code> allows Linq to perform more usefully. Specifically, you can't get <code>Into Max(Anon.SomeString)</code> to work with <code>Option Strict Off</code>, though there are a number of workarounds.</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