C#等于VBA" with..end with“声明 [英] C# equivelent of VBA "with..end with" statement

查看:133
本文介绍了C#等于VBA" with..end with“声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我,如果有一个C#等于VBA''和''

语句,就像这样:


设置myControl = CommandBars(PopUpToUse).Controls.Add(msoControlBut ton,

before:= 5)

使用myControl

.BeginGroup = True

.Caption =" Insert Row(s)"

.OnAction =" InsertRows"

.FaceId = 295

结束

谢谢

Can someone tell me if there is a C# equivelent to the VBA ''with''
statement that works like this:

Set myControl = CommandBars(PopUpToUse).Controls.Add(msoControlBut ton,
before:=5)
With myControl
.BeginGroup = True
.Caption = "Insert Row(s)"
.OnAction = "InsertRows"
.FaceId = 295
End With
Thanks

推荐答案

Mike N.< mi ********** ***@gmail.com写道:
Mike N. <mi*************@gmail.comwrote:

有人可以告诉我,如果VBA中有一个C#等于'''

声明如下:
Can someone tell me if there is a C# equivelent to the VBA ''with''
statement that works like this:



不,没有。 C#3有对象初始化器,所以当你调用一个

构造函数(并且只在那个时候)你可以设置一堆属性,

像这样:


按钮按钮=新按钮{Text =" Hi",Size = ...};


同样有集合初始值设定项:


List< stringstrings = new List< string {" Hi"," There" };


但是没有With声明。


-

Jon Skeet - < sk *** @ pobox.com>

网站: http:// www .pobox.com / ~siget

博客: http://www.msmvps.com/jon.skeet

C#深度: http://csharpindepth.com

No, there isn''t. C# 3 has object initializers so that when you call a
constructor (and only at that time) you can set a bunch of properties,
like this:

Button button = new Button { Text = "Hi", Size = ... };

Likewise there are collection initializers:

List<stringstrings = new List<string{ "Hi", "There" };

But no With statement.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com


2008年6月6日星期五13:16:34 -0700,Mike N.< mi *************@gmail.com>

写道:
On Fri, 06 Jun 2008 13:16:34 -0700, Mike N. <mi*************@gmail.com>
wrote:

有人可以告诉我,如果有是一个C#等于VBA''与''

语句,如下所示:
Can someone tell me if there is a C# equivelent to the VBA ''with''
statement that works like this:



没有。


如果它让你感觉更好,那么在过去出现这种情况时,其他人已经指出了为什么VBAWith with声明可能导致维护

问题,特别是当它们嵌套时。 :)


Pete

There is none.

If it makes you feel better, when this has come up in the past, others
have pointed out why the VBA "With" statement can lead to maintenance
problems, especially when they are nested. :)

Pete


Peter Duniho写道:
Peter Duniho wrote:

2008年6月6日星期五13:16:34 -0700,Mike N.< mi ************* @ gmail.com>

写道:
On Fri, 06 Jun 2008 13:16:34 -0700, Mike N. <mi*************@gmail.com>
wrote:

>有人可以告诉我,如果有一个C#等于VBA''with''
语句是这样的:
>Can someone tell me if there is a C# equivelent to the VBA ''with''
statement that works like this:



没有。


如果它让你感觉更好,过去曾经出现过,其他人

已经指出了为什么VBAWith和声明可能导致维护

问题,特别是当它们嵌套时。 :)


There is none.

If it makes you feel better, when this has come up in the past, others
have pointed out why the VBA "With" statement can lead to maintenance
problems, especially when they are nested. :)



但有趣的是,通常那些使用语言

没有WITH(C ++,Java,C#) )认为这是一个问题。

实际使用它的那些(在VB或Pascal中)并不认为这个问题是一个真正的问题。


Arne

But it is rather interesting that it is usually those that use languages
that does not have WITH (C++, Java, C#) that think it is a problem.
Those that actually have used it (in VB or Pascal) does not see
that problem as a real problem.

Arne


这篇关于C#等于VBA&quot; with..end with“声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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