Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Can someone tell me the difference between these two ways to get the wanted result?

VB
Dim x1 = db.t_Articles.First(Function(x) x.StorageUnit = "some unit")
Dim x2 = (From x In db.t_Articles Where x.StorageUnit = "some unit").First


Thank you
Posted

In terms of performance, there's no difference at all between the two. They both boil down to exactly the same IL:
.method private hidebysig static bool  '<main>b__3'(class LinqIl.Article x) cil managed
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) 
  // Code size       21 (0x15)
  .maxstack  2
  .locals init ([0] bool CS$1$0000)
  IL_0000:  ldarg.0
  IL_0001:  ldfld      string LinqIl.Article::StorageUnit
  IL_0006:  ldstr      "some unit"
  IL_000b:  call       bool [mscorlib]System.String::op_Equality(string,
                                                                 string)
  IL_0010:  stloc.0
  IL_0011:  br.s       IL_0013
  IL_0013:  ldloc.0
  IL_0014:  ret
} // end of method Program::'<main>b__3'</main></main>
If you want to prove this to yourself, all you need to do is run ildasm and disassemble your code.
 
Share this answer
 
Comments
DamithSL 23-May-14 5:31am    
for me it was bit different in LINQ pad generated IL.
Answer is Here in SO[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900