Any Equivalent to VB.NET's With...End With Statement ...

A

Ashok Guduru

Hi,

I'm new to C#. In VB.NET we have With...End With Statement. Often, I need to
perform several different actions on the same object. For example, I may
need to set several properties or execute several methods for the same
object.

Private Sub UpdateForm()

Button1.Text = "OK"
Button1.Visible = True
Button1.Top = 24
Button1.Left = 100
Button1.Enabled = True
Button1.Refresh()

End Sub

You can write the same in short form like this.

Private Sub UpdateForm2()

With Button1

.Text = "OK"
.Visible = True
.Top = 24
.Left = 100
.Enabled = True
.Refresh()

End With

End Sub

Is there any such facility available in C# too?

Regards,

G.Ashok
 
J

Josip Medved

I'm new to C#. In VB.NET we have With...End With Statement. Often, I need to
Is there any such facility available in C# too?

No.
"They" say it hurts code clarity...
 
P

Peter Morris [Droopy eyes software]

"They" say it hurts code clarity...

Much worse than that, it makes it very easy to introduce bugs in order parts
of your code by adding new properties/methods to classes.
 
C

Christof Nordiek

Hi Peter,

could you explain how? just curious.

Peter Morris said:
Much worse than that, it makes it very easy to introduce bugs in order
parts of your code by adding new properties/methods to classes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top