是否与&QUOT任何性能优势;链"在.NET中陈述?性能、优势、QUOT、NET

由网友(无所的畏惧)分享简介:当从表中检索查找code值,有些人做到这一点...... When retrieving a lookup code value from a table, some folks do this...Dim dtLookupCode As New LookupCodeDataTable()Dim taLookup...

当从表中检索查找code值,有些人做到这一点......

When retrieving a lookup code value from a table, some folks do this...

Dim dtLookupCode As New LookupCodeDataTable()
Dim taLookupCode AS New LookupCodeTableAdapter()
Dim strDescription As String

dtLookupCode = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL")
strDescription = dtLookupCode.Item(0).Meaning

...但是,我也看到了事情做好链接像这样...

...however, I've also seen things done "chained" like this...

strDescription = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL").Item(0).Meaning

...绕过其摆在首位查找code数据表,因为表适配器知道其结果集的结构样子。

...which bypasses having a lookup code data table in the first place since the table adapter knows what the structure of its result set looks like.

是否使用链接方式保存创建数据表对象的开销,还是它有效地得到反正为了妥善处理.Item(0).Meaning语句创建的?

Does using the "chained" method save the overhead of creating the data table object, or does it effectively get created anyway in order to properly handle the .Item(0).Meaning statement?

推荐答案

从这个内联的部分偏离,其实,这两套code不会编译出同样的事情。这个问题开始与:

Straying from the "inline" part of this, actually, the two sets of code won't compile out to the same thing. The issue comes in with:

Dim dtLookupCode As New LookupCodeDataTable()
Dim taLookupCode AS New LookupCodeTableAdapter()

在VB中,这将创建一个适合的名字引用新的对象。其次是:

In VB, this will create new objects with the appropriately-named references. Followed by:

dtLookupCode = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL")

我们立即更换一个新的对象,这就造成垃圾收集(RAM中的不可达的对象)的原 dtLookup code 引用。

We immediately replace the original dtLookupCode reference with a new object, which creates garbage to be collected (an unreachable object in RAM).

在准确,原始方案,因此,什么是被称为内联技术,技术上的,更好的性能。 (但是,你不可能实际看到这个小的例子不同。)

In the exact, original scenario, therefore, what's referred to as the "inline" technique is, technically, more performant. (However, you're unlikely to physically see that difference in this small an example.)

其中code将基本上是一样的地方是,如果原始样本如下:

The place where the code would essentially be the same is if the original sample read as follows:

Dim taLookupCode AS New LookupCodeTableAdapter
Dim dtLookupCode As LookupCodeDataTable
Dim strDescription As String

dtLookupCode = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL")
strDescription = dtLookupCode.Item(0).Meaning

在这个世界上,我们只有现有的参考,并且不产生垃圾的对象。我稍微重新排序的语句是为了便于阅读,但要点是相同的。此外,你可以很容易的单线初始化与引用这​​样的事情,并且具有相同的基本思想是:

In this world, we only have the existing references, and are not creating junk objects. I reordered the statements slightly for readability, but the gist is the same. Also, you could easily single-line-initialize the references with something like this, and have the same basic idea:

Dim taLookupCode AS New LookupCodeTableAdapter
Dim dtLookupCode As LookupCodeDataTable = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL")
Dim strDescription As String = dtLookupCode.Item(0).Meaning
阅读全文

相关推荐

最新文章