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

前端 未结 5 532
借酒劲吻你
借酒劲吻你 2021-01-17 17:52

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         


        
相关标签:
5条回答
  • 2021-01-17 17:52

    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
    };
    
    0 讨论(0)
  • 2021-01-17 17:55

    There's something called using, but compared to Delphi/Pascal it's works more like try/finally.

    0 讨论(0)
  • 2021-01-17 18:03

    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
       };
    
    0 讨论(0)
  • 2021-01-17 18:03

    No, that does not exist in C#.

    0 讨论(0)
  • 2021-01-17 18:11

    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;
    
    0 讨论(0)
提交回复
热议问题