关于LINQ //性能的问题 [英] Question about LINQ // performance

查看:73
本文介绍了关于LINQ //性能的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

有人能告诉我这两种获得想要结果的方法之间的区别吗?



Hi
Can someone tell me the difference between these two ways to get the wanted result?

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

推荐答案

就性能而言,两者之间没有任何区别。它们都归结为完全相同的IL:
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:ldstrsome 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
} //方法结束程序::'< main> b__3'< / main> ;< / main>
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>

如果你想向自己证明这一点,你需要做的就是运行ildasm和disassembl你的代码。

If you want to prove this to yourself, all you need to do is run ildasm and disassemble your code.


这篇关于关于LINQ //性能的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆