vb.net - Proper use of shared vars in Visual Basic.NET -
class klass private shared state boolean public sub savestate (byval value boolean) state = value end sub public function getstate () boolean return state end function private sub work() savestatet(false) end sub private sub work2() if getstate() .... end sub ... end class
is correct use shared variables in way or accessing them state = false, , if state... something
.
usually done using property clearer syntax, but, per se, not wrong using couple of get/set functions.
private shared internalstate boolean public property state() boolean return internalstate end set(byval value boolean) internalstate = value end set end property
but keep in mind shared variable 'shared' between every instance of class. if declare
dim c1 = new klass() c1.state = true dim c2 = new klass() console.writeline(c2.tostring) ' prints true'
i want add using property way better in terms of usability when have ide suggest members of class intellisense feature. have 1 item (the property name) search , not 2 names of methods, related scattered alphabetically. (getstate, savestate)
Comments
Post a Comment