Warm tip: This article is reproduced from serverfault.com, please click

.net-在C#中,Delphi的“ with”命令是否等效?

(.net - Is there an equivalent for Delphi's "with" command in c#?)

发布于 2011-05-19 07:58:53

我想知道在C#中是否有可以像with command在Delphi中那样使用的命令

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

//在Delphi中

with edit1 do 
 begin
   text="some text as text of edit1";
   tag=1231;
 end;
Questioner
Mohsen
Viewed
0
Alex Aza 2014-12-29 10:17:47

不适用于已经创建的实例。

但是,创建新实例时,你可以执行以下操作:

var textbox1 = 
   new Textbox
   {
       Text = "some text as text of text box",
       Tag = 1231
   };