开发者

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

开发者 https://www.devze.com 2022-12-22 02:52 出处:网络
Apparently, this does not work. WHY ??????? I don\'t want to do all this just to call my function: Dim x as new Object()

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 t开发者_Go百科wo lines when I can in one.


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消