与条款 [英] With Clause

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

问题描述

我非常尊重Herfried& Cor的反应和自从两个冲突后,我想得到一些澄清。


我的原始帖子:

Herfried,也许你在这里的例子可以让你回答一个问题我已经想了一段时间。


随着Me.Label1

.Text = ...

.Refresh()

结束


背后的想法子句是允许更快的执行,因为

Me在你的例子中,ojbect不必解决2次。但是

你可以用我重写你的样品


使用Label1

.Text = ...

.Refresh()

结束


在这种情况下,由于你实际上不是

消除点。我的想法是否正确?


Herfried的回复

我。即使没有明确写出也会得到解决。在这种情况下,我使用
使用类型代码更快;-)。

Cor'的Retanse

ME"仅适用于程序员,它在运行时不执行任何操作。

With子句在程序中创建一个额外的引用。在这种情况下它会比没有With子句的程序慢,但是想想比

可能只有几纳秒的时间。

我希望这提供了一些想法吗?

I have come to greatly respect both Herfried & Cor''s reponses and since the
two conflicted, I wanted to get some clarification.

My orginal post:
Herfried, maybe your example here can get you to answer a question I''ve
wondered about for a while.

With Me.Label1
.Text = ...
.Refresh()
End With

The idea behind the With clause is it allows for faster execution since
the "Me" ojbect doesn''t have to be resolved 2 times in your example. But
you could rewrite your sample w/o the Me

With Label1
.Text = ...
.Refresh()
End With

In this case there wouldn''t be any inhancement since you are not actually
eliminating the dot. Am I correct in my thinking?

Herfried''s response
The ''Me.'' is resolved even if it''s not explicitly written. In this case I
used With type the code faster ;-).

Cor''s Reposnse
The "Me" is only for the programmer, it does nothing at runtime.
The With clause creates an extra reference in a program. In this case it
will be slower than a program without a With clause, however think than
probably in parts of nanoseconds.
I hope this gives some ideas?


推荐答案

Chris,


这里来自这个程序的IL代码(我已经准备好当Herfried

会做出反应但是他没有);-)


Public Sub test()

使用Me.label1

.Text =" Me"

.Refresh()



带标签1

.Text =不带我

.Refresh()

结束

label1.Text =" without With"

label1.Refresh()


End Sub

\\\ \\ / $
IL_0000:ldarg.0

IL_0001:ldfld类

[System.Windows.Forms] System.Windows.Forms.Label Testje。 Class1 :: label1

IL_0006:stloc.1

IL_0007:ldloc.1

IL_0008: ldstr我

IL_000d:callvirt实例void

[System.Windows.Forms] System.Windows.Forms.Control :: set_Text(string)

IL_0012:ldloc.1

IL_0013:callvirt instance void

[System.Windows.Forms] System.Windows.Forms.Control :: Refresh()

IL_0018:ldnull

IL_0019:stloc.1

IL_001a:ldarg.0

IL_001b:ldfld class

[System.Windows.Forms] System.Windows.Forms.Label Testje.Class1 :: label1

IL_0020:stloc.0

IL_0021:ldloc .0

IL_0022:ldstr没有我

IL_0027:callvirt实例void

[System.Windows.Forms] System.Windows。 Forms.Control :: set_Text(string)

IL_002c:ldloc.0

IL_002d:callvirt instance void

[System.Windows.Forms] System.Windows.Forms.Control :: Refresh()

IL_0032:ldnull

IL_0033:stloc.0

IL_0034:ldarg.0

IL_0035: ldfld类

[System.Windows.Forms] System.Windows.Forms.Label Testje.Class1 :: label1

IL_003a:ldstr" without With"

IL_003f:callvirt instance void

[System.Windows.Forms] System.Windows.Forms.Control :: set_Text(string)

IL_0044:ldarg.0

IL_0045:ldfld类

[System.Windows.Forms] System.Windows.Forms.Label Testje.Class1 :: label1

IL_004a: callvirt实例void

[System.Windows.Forms] System.Windows.Forms.Control :: Refresh()

IL_004f:ret

/ //
Chris,

Here the IL code from this program (I had it already ready when Herfried
would react however he did not) ;-)

Public Sub test()
With Me.label1
.Text = "Me"
.Refresh()
End With
With label1
.Text = "without Me"
.Refresh()
End With
label1.Text = "without With"
label1.Refresh()

End Sub
\\
IL_0000: ldarg.0
IL_0001: ldfld class
[System.Windows.Forms]System.Windows.Forms.Label Testje.Class1::label1
IL_0006: stloc.1
IL_0007: ldloc.1
IL_0008: ldstr "Me"
IL_000d: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_0012: ldloc.1
IL_0013: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::Refresh()
IL_0018: ldnull
IL_0019: stloc.1
IL_001a: ldarg.0
IL_001b: ldfld class
[System.Windows.Forms]System.Windows.Forms.Label Testje.Class1::label1
IL_0020: stloc.0
IL_0021: ldloc.0
IL_0022: ldstr "without Me"
IL_0027: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_002c: ldloc.0
IL_002d: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::Refresh()
IL_0032: ldnull
IL_0033: stloc.0
IL_0034: ldarg.0
IL_0035: ldfld class
[System.Windows.Forms]System.Windows.Forms.Label Testje.Class1::label1
IL_003a: ldstr "without With"
IL_003f: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_0044: ldarg.0
IL_0045: ldfld class
[System.Windows.Forms]System.Windows.Forms.Label Testje.Class1::label1
IL_004a: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::Refresh()
IL_004f: ret
///


但是如果你以另一种方式看待它,如果你考虑访问一个属性为

指针间接的多个层次,并且没有使用make更快通过

删除几个级别的间接?


Rgds,

Anand M
http://www.dotnetindia.com


克里斯,万事万物的大师写道:
But if you look at it another way, if you consider a access to a property as
multiple levels of indirection of a pointer, does''nt With make is faster by
removing a few levels of indirection?

Rgds,
Anand M
http://www.dotnetindia.com

"Chris, Master of All Things Insignifican" wrote:
我非常尊重Herfried& Cor的反应和自两个冲突后,我想得到一些澄清。

我的原始帖子:
Herfried,也许你的例子在这里可以让你回答一个问题我已经好好想了一会儿。

随着Me.Label1
.Text = ...
.Refresh()
结束随着

With子句背后的想法是它允许更快的执行,因为我是我。在你的例子中,ojbect不必解决2次。但是
你可以用我来重写你的样本

使用Label1
.Text = ...
.Refresh()
结束

在这种情况下,由于你实际上没有消除点,所以不会有任何增强。我的想法是否正确?

Herfried的回答
即使没有明确写出,我也会得到解决。在这种情况下,我使用With代码更快地输入代码;-)。

Cor'的Reposnse
The Me"仅适用于程序员,它在运行时不执行任何操作。
With子句在程序中创建一个额外的引用。在这种情况下,它会比没有With子句的程序慢,但是想想比
可能在几纳秒的时间内。
我希望这会给出一些想法吗?
I have come to greatly respect both Herfried & Cor''s reponses and since the
two conflicted, I wanted to get some clarification.

My orginal post:
Herfried, maybe your example here can get you to answer a question I''ve
wondered about for a while.

With Me.Label1
.Text = ...
.Refresh()
End With

The idea behind the With clause is it allows for faster execution since
the "Me" ojbect doesn''t have to be resolved 2 times in your example. But
you could rewrite your sample w/o the Me

With Label1
.Text = ...
.Refresh()
End With

In this case there wouldn''t be any inhancement since you are not actually
eliminating the dot. Am I correct in my thinking?

Herfried''s response
The ''Me.'' is resolved even if it''s not explicitly written. In this case I
used With type the code faster ;-).

Cor''s Reposnse
The "Me" is only for the programmer, it does nothing at runtime.
The With clause creates an extra reference in a program. In this case it
will be slower than a program without a With clause, however think than
probably in parts of nanoseconds.
I hope this gives some ideas?



谢谢,你刚才证明我的思路正确。


Chris


" Cor Ligthert" <无************ @ planet.nl>在消息中写道

news:up ************** @ TK2MSFTNGP12.phx.gbl ...
Thanks, you just proved that I was thinking correctly.

Chris

"Cor Ligthert" <no************@planet.nl> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
Chris,
这里有来自这个程序的IL代码(我已经准备好当Herfried
会做出反应但是他没有);-)

公共子测试()
使用Me.label1
.Text =" Me"
.Refresh()
结束
使用label1
.Text =" without Me"
.Refresh()
结束
label1.Text =" without With"
label1.Refresh()

End Sub
\ \\ _
IL_0000:ldarg.0
IL_0001:ldfld类
[System.Windows.Forms] System.Windows.Forms.Label Testje.Class1 :: label1
IL_0006:stloc .1
IL_0007:ldloc.1
IL_0008:ldstr" Me"
IL_000d:callvirt instance void
[System.Windows.Forms] System.Windows.Forms.Control: :set_Text(string)
IL_0012:ldloc.1
IL_0013:callvirt instance void
[System.Windows.Forms] System.Windows.Forms.Control :: Refresh()
IL_0018:ldnull
IL_0019:stloc.1
IL_001a:ldarg.0
IL_001b:ldfld类
[System.Windows.Forms] System.Windows.Forms.Label Testje.Class1 :: label1
IL_0020:stloc.0
IL_0021:ldloc.0
IL_0022:ldstr没有我
IL_0027:callvirt实例void
[System.Windows.Forms] System.Windows.Forms.Control :: set_Text(string)
IL_002c:ldloc.0
IL_002d:callvirt实例void
[System.Windows.Forms] System.Windows.Forms.Control :: Refresh()
IL_0032:ldnull
IL_0033:stloc.0
IL_0034:ldarg.0
IL_0035:ldfld类
[System.Windows.Forms] System.Windows.Forms.Label Testje.Class1 :: label1
IL_003a:ldstr" without With" ; IL_003f:callvirt实例void
[System.Windows.Forms] System.Windows.Forms.Control :: set_Text(string)
IL_0044:ldarg.0
IL_0045: ldfld类
[System.Windows.Forms] System.Windows.Forms.Label Testje.Class1 :: label1
IL_004a:callvirt instance void
[System.Windows.Forms] System.Windows。 Forms.Control :: Refresh()
IL_004f:ret
///
Chris,

Here the IL code from this program (I had it already ready when Herfried
would react however he did not) ;-)

Public Sub test()
With Me.label1
.Text = "Me"
.Refresh()
End With
With label1
.Text = "without Me"
.Refresh()
End With
label1.Text = "without With"
label1.Refresh()

End Sub
\\
IL_0000: ldarg.0
IL_0001: ldfld class
[System.Windows.Forms]System.Windows.Forms.Label Testje.Class1::label1
IL_0006: stloc.1
IL_0007: ldloc.1
IL_0008: ldstr "Me"
IL_000d: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_0012: ldloc.1
IL_0013: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::Refresh()
IL_0018: ldnull
IL_0019: stloc.1
IL_001a: ldarg.0
IL_001b: ldfld class
[System.Windows.Forms]System.Windows.Forms.Label Testje.Class1::label1
IL_0020: stloc.0
IL_0021: ldloc.0
IL_0022: ldstr "without Me"
IL_0027: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_002c: ldloc.0
IL_002d: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::Refresh()
IL_0032: ldnull
IL_0033: stloc.0
IL_0034: ldarg.0
IL_0035: ldfld class
[System.Windows.Forms]System.Windows.Forms.Label Testje.Class1::label1
IL_003a: ldstr "without With"
IL_003f: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_0044: ldarg.0
IL_0045: ldfld class
[System.Windows.Forms]System.Windows.Forms.Label Testje.Class1::label1
IL_004a: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::Refresh()
IL_004f: ret
///



这篇关于与条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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