You can use the VB object initializer syntax with the Infer option:
Dim variable As New SomeClass With { .AString = "Hello", .AnInteger = 12345 } return variable
You still have a variable, but it's pretty clean.
If you do not need a variable, you can try the code as follows:
Return New SomeClass With { .AString = "Hello", .AnInteger = 12345 }
I do not believe that this syntax allows you to call methods on an instance. I think you can only set properties.
source share