使用 - 以C#结束块 [英] With - End with block in C#

查看:69
本文介绍了使用 - 以C#结束块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我最近从VB6搬到了C#,对

结果非常满意。但是,我想念这一个功能。我能找到的最接近的是b $ b找到的是使用语句,但它需要对象实现

IDisposable接口,它不会省去键入

变量名称的麻烦。我想做的是类似于这个vb6

代码块:


Dim a as class1

set a =新上课1

,带

.dothis

.dothat

.propertyx = 1

结束


C#中是否存在类似的功能,或者没有?


祝你好运,


Zeljko

解决方案

不,它不存在。


Miha


" Zeljko" < TR ******* @ yahoo.com>在消息中写道

news:d5 ******************************** @ 4ax.com ...



我最近从VB6转到C#,对结果非常满意。但是,我想念这一个功能。我能找到的最接近的东西是使用。声明,但它需要对象实现IDisposable接口,它不会省去键入
变量名称的麻烦。我想做的是类似于这个vb6
代码块:

Dim a as class1
set a = new class1
with a
.dothis
.dothat
.propertyx = 1
结束

C#中是否存在类似的功能,或者没有?

最好的问候,

Zeljko



Zeljko< tr ******* @ yahoo.com>写道:

我最近从VB6转到C#,对
结果非常满意。但是,我想念这一个功能。我能找到的最接近的东西是使用。声明,但它需要对象实现IDisposable接口,它不会省去键入
变量名称的麻烦。


事实上,使用和有分享基本上没有特色:)

我想做的是类似于这个vb6
代码块:

Dim a as class1
set a = new class1

.dothis
.dothat
.propertyx = 1
结束

类似的功能是否存在于C#,还是没有?




不,它没有。 (谢天谢地,在我看来。)


http://www.gotdotnet.com/team/csharp.../ask.aspx#with

因为它的原因不在C#中。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复该组,请不要给我发邮件


2003年10月28日星期二16:21:49 +0100,Zeljko< tr ***** **@yahoo.com>写道:



我最近从VB6转到了C#,对结果非常满意。但是,我想念这一个功能。我能找到的最接近的东西是使用。声明,但它需要对象实现IDisposable接口,它不会省去键入
变量名称的麻烦。我想做的是类似于这个vb6
代码块:

Dim a as class1
set a = new class1
with a
.dothis
.dothat
.propertyx = 1
结束

C#中是否存在类似的功能,或者没有?




在学习如何思考更多OOP的过程中,我想通过

... End With是一个好主意,只有像旧的VB这样的语言很差OOP

功能。

当你发现自己在同一个对象上进行一系列操作时,你需要通过b
$ b该对象的类的方法或

新的继承类。一旦代码在正在执行的类中打开,对象引用就变得隐含了,就像它在With

块中一样。


Hi,

I moved from VB6 to C# recently, and am very satisfied with the
result. However, I miss this one feature. The closest thing I could
find is "using" statement, but it requires object to implement
IDisposable interface, and it won''t save me the trouble of typing the
variable name. What I want to do is something similar to this vb6
block of code:

Dim a as class1
set a = new class1
with a
.dothis
.dothat
.propertyx = 1
end with

Does the similar feature exist in C#, or no ?

Best regards,

Zeljko

解决方案

No, it does not exist.

Miha

"Zeljko" <tr*******@yahoo.com> wrote in message
news:d5********************************@4ax.com...

Hi,

I moved from VB6 to C# recently, and am very satisfied with the
result. However, I miss this one feature. The closest thing I could
find is "using" statement, but it requires object to implement
IDisposable interface, and it won''t save me the trouble of typing the
variable name. What I want to do is something similar to this vb6
block of code:

Dim a as class1
set a = new class1
with a
.dothis
.dothat
.propertyx = 1
end with

Does the similar feature exist in C#, or no ?

Best regards,

Zeljko



Zeljko <tr*******@yahoo.com> wrote:

I moved from VB6 to C# recently, and am very satisfied with the
result. However, I miss this one feature. The closest thing I could
find is "using" statement, but it requires object to implement
IDisposable interface, and it won''t save me the trouble of typing the
variable name.
In fact, "using" and "with" share basically no characteristics :)
What I want to do is something similar to this vb6
block of code:

Dim a as class1
set a = new class1
with a
.dothis
.dothat
.propertyx = 1
end with

Does the similar feature exist in C#, or no ?



No, it doesn''t. (Thanks goodness, in my view.)

See http://www.gotdotnet.com/team/csharp.../ask.aspx#with
for the reasons it''s not in C#.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


On Tue, 28 Oct 2003 16:21:49 +0100, Zeljko <tr*******@yahoo.com> wrote:

Hi,

I moved from VB6 to C# recently, and am very satisfied with the
result. However, I miss this one feature. The closest thing I could
find is "using" statement, but it requires object to implement
IDisposable interface, and it won''t save me the trouble of typing the
variable name. What I want to do is something similar to this vb6
block of code:

Dim a as class1
set a = new class1
with a
.dothis
.dothat
.propertyx = 1
end with

Does the similar feature exist in C#, or no ?



In the course of learning how to think more OOP, Ive figured out that With
... End With is a good idea only in a language like the old VB with poor OOP
capabilities.
When you find yourself doing a series of operations on the same object, you
usually have a case for making this a method of that object''s class or a
new inheriting class. Once the code is in the class that is being acted
on, the object reference becomes implicit, just as it would be in a With
block.


这篇关于使用 - 以C#结束块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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