Instantiate Class and call method on same line

dan-cat

New member
Joined
Jul 7, 2011
Messages
2
Programming Experience
5-10
Hello,

I'm sure I've seen this done in 4.0 but can't remember how it is done.

Basically I want to instantiate a class and call a method of that class on the same line of code.

So something like this


VB.NET:
Dim s as String = new myClass().getTestString()

Any help much appreciated.

Thanks

Dan
 
Ok, that's embarrassing, the example I gave is actually how you do it. Just need to remember the parenthesis with the constructor.
 
If the method doesn't depend on instance data it could be declared Shared.
 
Back
Top