与 C# 中的块等效? [英] With block equivalent in C#?
问题描述
我了解 VB.Net 并且正在尝试复习我的 C#.C# 中是否有 With
块等效?
I know VB.Net and am trying to brush up on my C#. Is there a With
block equivalent in C#?
推荐答案
这是 Visual C# 程序经理不得不说的:为什么不t C# 有with"语句?
This is what Visual C# program manager has to say: Why doesn't C# have a 'with' statement?
许多人,包括 C# 语言设计者,都相信与"通常会损害可读性,这与其说是一种祝福,不如说是一种诅咒.这是更清晰地声明具有有意义名称的局部变量,并使用该变量对单个对象执行多个操作,而不是它是有一个带有某种隐式上下文的块.
Many people, including the C# language designers, believe that 'with' often harms readability, and is more of a curse than a blessing. It is clearer to declare a local variable with a meaningful name, and use that variable to perform multiple operations on a single object, than it is to have a block with a sort of implicit context.
这篇关于与 C# 中的块等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!