Is there an equivalent to VB.Net Call in C #?

2

The question is simple. Is there a keyword equivalent to Call of Visual Basic .NET in C #?

In Visual Basic, I called a method of a class without explicitly declaring a member for it:

Call New Form() With {.Text = "Olá, mundo!"}.ShowDialog()

This all above would be the equivalent of this in C #:

Form tmp = new Form() { Text = "Olá, mundo!" };
tmp.ShowDialog();
tmp.Dispose();

I find this keyword very useful because it saves space on code, organization, and memory management by discarding used objects after the end of use.

Is there any way to call a member, lambda , or procedure that Call does, but in C #?

    
asked by anonymous 01.08.2017 / 05:25

1 answer

2

The equivalent in C # would be:

(new Form() { Text = "Olá, mundo!" }).ShowDialog();

You may be wondering where the 3rd is. line. It should exist in the version in VB.NET as well, since it chose not to have not have to add in C #.

In fact, this code does not make much sense.

The apparent economy of VB.NET is just because it does far less than the C # version, even in variable assignment which is one more operation that the code is doing. It's not the Call that's helping, it's the fact that the code does less. In fact comparing to C #, like almost everything in VB.NET, the code gets more verbose if you do the same thing.

    
01.08.2017 / 06:12