Tomasi
Tomasi

Reputation: 2509

(New Object()).Method() in VB.net

Apparently, this does not work.

WHY ???????

I don't want to do all this just to call my function:

Dim x as new Object()
x.Method()

Why do I have to do this in two lines when I can in one.

Upvotes: 7

Views: 2629

Answers (2)

user274769
user274769

Reputation: 1

I'm assuming you don't want to make the method static?

public class foo
    public shared sub sayFoo
        console.writeline("foo")
    end sub
end class

then call sayFoo like.

foo.sayFoo

Upvotes: -1

AMissico
AMissico

Reputation: 21684

You need to add the Call keyword.

    Call New Page().DataBind()

This causes the object to be created before passing to the Call statement.

Yes, I agree, (New Object()).Method() seems more intuitive.

Upvotes: 12

Related Questions