vb.net - Constructing an object without assigning it in Visual Basic.NET -
i've used vb.net several years now, keep coming across little quirks don't know how work around. curiosity got best of me, ask now: is there way create object without assigning it?
for example, have engine class, want instantiate , have whatever needs do. if there's nothing need engine after creating it, have, till now, done like:
dim myengine new engine()
is there way avoid "dim myengine as" part? can in java. create object "new engine()" in java , not assign anything.
why need this? because want create delegate object (hence called "engine") performs functionality, otherwise don't need ever reference it. used have such objects have "public sub perform", have found cumbersome -- i'd rather create object , not worry remembering call perform method. , find aesthetically displeasing create references objects don't intend use.
any vb guru have suggestion?
thanks,
-- michael
to need put new declaration inside parentheses ( )
you can try syntax:
call new theclass().method1()
or:
dosomething(new theclass())
or even:
dosomething(new theclass().getstringdata())
source: http://tutorials.beginners.co.uk/vb-net-programming-part-6-interacting-with-objects.htm
Comments
Post a Comment