Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent for Delphi's "with" command in c#?

I was wondering if there is a command in C# which I can use like with command in Delphi?

// like this :
with(textbox1)
{
   .text="some text as text of text box";
   .tag=1231;
}

// in Delphi

with edit1 do 
 begin
   text="some text as text of edit1";
   tag=1231;
 end;
like image 846
Mohsen Avatar asked May 19 '11 07:05

Mohsen


3 Answers

No, that does not exist in C#.

like image 67
driis Avatar answered Nov 01 '22 04:11

driis


No, it does not exist in C#, however, when creating an object, you can do like this:

var textbox1 = new TextBox {
    Text = "some text as text of text box";
    Tag = 1231
};
like image 4
Markus Johnsson Avatar answered Nov 01 '22 04:11

Markus Johnsson


Not for already created instances.

However, when you create a new instance you can do:

var textbox1 = 
   new Textbox
   {
       Text = "some text as text of text box",
       Tag = 1231
   };
like image 14
Alex Aza Avatar answered Nov 01 '22 03:11

Alex Aza