Custom Search

Sunday, September 30, 2007

How to you use Friend and Class in VB.Net

imports system

class singleton
public shared s as singleton
public shared flag as boolean
public i as String

private sub new
' private constructor disallowing other to create object directly
end sub

friend shared function getSingletonObject as singleton
if flag = false then
s = new singleton
flag = true
return s
return s
end if
end function
end class

class test
shared sub main
dim o as singleton
dim y as singleton
o = singleton.getSingletonObject
o.i = "Singleton"
y = singleton.getSingletonObject
end sub
end class

No comments: