问题
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;
回答1:
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
};
回答2:
No, that does not exist in C#.
回答3:
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
};
回答4:
No but depending on what you are trying to do, the following would work:
TextBox t = textbox1;
t.text="some text as text of text box";
t.tag=1231;
回答5:
There's something called using, but compared to Delphi/Pascal it's works more like try/finally.
来源:https://stackoverflow.com/questions/6055552/is-there-an-equivalent-for-delphis-with-command-in-c