Is there equivalent to VB.NET Call in C#?

Asked

Viewed 82 times

2

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

In Visual Basic, I called a class method without having to declare a member explicitly to it:

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

All this 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 in code, organization and memory management, because it discards the objects used after the end of use.

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

1 answer

2


The equivalent in C# would be:

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

I put in the Github for future reference.

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

Actually this code doesn’t make much sense at all.

The apparent saving of VB.NET is only because it does much less than the version of C#, even in the variable assignment that is one more operation that the code is doing. Is not the Call It’s the fact that the code does less. Actually comparing to C#, as almost everything in VB.NET, the code becomes more verbose if you do the same thing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.