C# equivalent for Visual Basic keyword: 'With' … 'End With'?

后端 未结 7 1976
南笙
南笙 2020-12-11 04:21

In Visual Basic, if you are going to change multiple properties of a single object, there\'s a With/End With statement:

Dim myObject as Object

         


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 04:46

    Why doesn't C# have VB.NET's 'with' operator?

    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.

    by @Jon Skeet

提交回复
热议问题