缺少在C#中'与'关键字关键字

2023-09-03 03:11:41 作者:少年的梨涡

我一直在寻找的Infragistics的控件库,今天的在线帮助,看到一些VB code,所使用的随着关键字选项卡控件设置多个属性。它已经近10年,因为我已经做任何VB编程,和我所有,但忘了这个关键字,即使存在。因为我还是比较新的C#,我赶紧去,看它是否也有类似的结构。可悲的是,我一直没能找到任何东西。

I was looking at the online help for the Infragistics control library today and saw some VB code that used the With keyword to set multiple properties on a tab control. It's been nearly 10 years since I've done any VB programming, and I had all but forgotten that this keyword even existed. Since I'm still relatively new to C#, I quickly went to see if it had a similar construct. Sadly, I haven't been able to find anything.

请问C#有一个关键字或类似的结构模仿的随着关键字在VB提供的功能?如果没有,是否有技术上的原因,为什么C#没有这个?

Does C# have a keyword or similar construct to mimic the functionality provided by the With keyword in VB? If not, is there a technical reason why C# does not have this?

编辑:我搜索了这个问我的问题之前,现有的条目,但没有找到一个雷所指(的这里)。要细化问题,那么,是否有技术上的原因,为什么C#没有这个?而古勒扎尔钉它 - 不,不会有一个技术原因,C#不具有的在关键字。这是由语言设计者设计决策。

I searched for an existing entry on this before asking my question, but didn't find the one Ray referred to (here). To refine the question, then, is there a technical reason why C# does not have this? And Gulzar nailed it - no, there are not a technical reason why C# does not have a With keyword. It was a design decision by the language designers.

推荐答案

这是什么C#项目经理说: 为什么不是C#有一个'与'语句?

This is what C# program manager has to say: Why doesn't C# have a 'with' statement?

  

小或不存在的可读性的优点。我们认为可读性的优点是小的或者不存在的。我不会去尽可能地说,with语句,使code的可读性变差,但有些人可能会。

Small or non-existent readability benefits. We thought the readability benefits were small or non-existent. I won't go as far as to say that the with statement makes code less readable, but some people probably would.

增加语言的复杂性。 with语句添加会使语言更复杂。例如,VB不得不添加新的语言的语法,以解决一个局部变量(文字)和属性之间的潜在的不确定性对与目标(。文)。解决这一问题的其他方法也介绍语言的复杂性。另一种方法是推动一个范围,使房地产隐藏的局部变量,但后来没有办法来引用本地没有加入一些转义语法。

Increased language complexity. Adding a with statement would make the language more complex. For example, VB had to add new language syntax to address the potential ambiguity between a local variable (Text) and a property on the "with" target (.Text). Other ways of solving this problem also introduce language complexity. Another approach is to push a scope and make the property hide the local variable, but then there's no way to refer to the local without adding some escape syntax.

C ++的遗产。 C ++从未有过with语句,而且缺乏这样的语句一般不被认为是用C ++开发的一个问题。此外,我们并没有感到其他的变化 - 正在写改变那种code的人,变化的平台,其他变化的语言,等等 - 与报表更加必要

C++ heritage. C++ has never had a with statement, and the lack of such a statement is not generally thought to be a problem by C++ developers. Also, we didn't feel that other changes -- changes in the kind of code people are writing, changes in the platform, other changes in the language, etc. -- made with statements more necessary.