Setters and Getters evil future [modified]
-
User Class part :
Public Property SetChallengedCardList() As Integer
Set(ByVal value As Integer)
_challengedCardList.Add(value)
End Set
Get
Return 0
End Get
End PropertyPublic Property GetChallengedCardList() As ArrayList
Set(ByVal value As ArrayList)
_challengedCardList = Nothing
End Set
Get
Return _challengedCardList
End Get
End Propertyand latter usage:
Dim u As New User()
u.SetChallengedCardList = 25
u.SetChallengedCardList = 27
u.SetChallengedCardList = 31;) :laugh:
sstanko78
modified on Thursday, April 16, 2009 6:07 AM
-
User Class part :
Public Property SetChallengedCardList() As Integer
Set(ByVal value As Integer)
_challengedCardList.Add(value)
End Set
Get
Return 0
End Get
End PropertyPublic Property GetChallengedCardList() As ArrayList
Set(ByVal value As ArrayList)
_challengedCardList = Nothing
End Set
Get
Return _challengedCardList
End Get
End Propertyand latter usage:
Dim u As New User()
u.SetChallengedCardList = 25
u.SetChallengedCardList = 27
u.SetChallengedCardList = 31;) :laugh:
sstanko78
modified on Thursday, April 16, 2009 6:07 AM
Proper solution would be:
Private _challengedCardList As ArrayList
Public Sub AddItemToChallengedCardList(ByVal value As Integer) \_challengedCardList.Add(value) End Sub Public ReadOnly Property GetChallengedCardList() As ArrayList Get Return \_challengedCardList End Get End Property
It was 21.00h in the office, so ....
sstanko78
-
Proper solution would be:
Private _challengedCardList As ArrayList
Public Sub AddItemToChallengedCardList(ByVal value As Integer) \_challengedCardList.Add(value) End Sub Public ReadOnly Property GetChallengedCardList() As ArrayList Get Return \_challengedCardList End Get End Property
It was 21.00h in the office, so ....
sstanko78
sstanko78 wrote:
Public ReadOnly Property GetChallengedCardList() As ArrayList
Get
Return _challengedCardList
End Get
End PropertyIsn't that mutable? You shouldn't return the whole array as it could then be changed from /outside/. Then puppy's cry.
Panic, Chaos, Destruction. My work here is done.
-
sstanko78 wrote:
Public ReadOnly Property GetChallengedCardList() As ArrayList
Get
Return _challengedCardList
End Get
End PropertyIsn't that mutable? You shouldn't return the whole array as it could then be changed from /outside/. Then puppy's cry.
Panic, Chaos, Destruction. My work here is done.
Hey, I'm used to returning the whole array, and I know that it then can be muted, but dno how to prevent this. Could you give an example of how it should be done? Cheers BN
My little forums: http://code.bn2vs.com 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
-
Hey, I'm used to returning the whole array, and I know that it then can be muted, but dno how to prevent this. Could you give an example of how it should be done? Cheers BN
My little forums: http://code.bn2vs.com 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
-
AFAIK you have to clone the array.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
dan neely wrote:
AFAIK you have to clone the array.
No, just wrap it:
System.Collections.Generic.List<string> mutable = new List<string>();
System.Collections.ObjectModel.ReadOnlyCollection<string> immutable = mutable.AsReadOnly();
Panic, Chaos, Destruction. My work here is done.
-
dan neely wrote:
AFAIK you have to clone the array.
No, just wrap it:
System.Collections.Generic.List<string> mutable = new List<string>();
System.Collections.ObjectModel.ReadOnlyCollection<string> immutable = mutable.AsReadOnly();
Panic, Chaos, Destruction. My work here is done.
-
Does that work with normal arrays as well as List<>'s?
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
Do I look like I know! :laugh: I was going to flippently say for usre, but I am unable to find it. In Java the base Collection supports immutable references, too late of evening for me to look, and so that goes through all the Map and Set classes. It seems a sensible approach; just not for M$.
Panic, Chaos, Destruction. My work here is done.
-
Do I look like I know! :laugh: I was going to flippently say for usre, but I am unable to find it. In Java the base Collection supports immutable references, too late of evening for me to look, and so that goes through all the Map and Set classes. It seems a sensible approach; just not for M$.
Panic, Chaos, Destruction. My work here is done.
OK. Until recently I've been doing 1.1 framework stuff :doh: , and was wondering if this was an new feature or something I'd managed to not discover in several years of using the language.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
-
dan neely wrote:
AFAIK you have to clone the array.
No, just wrap it:
System.Collections.Generic.List<string> mutable = new List<string>();
System.Collections.ObjectModel.ReadOnlyCollection<string> immutable = mutable.AsReadOnly();
Panic, Chaos, Destruction. My work here is done.
Thnx dude, didn't know that :)
GSoC 2009 student for SMW! --- My little forums: http://code.bn2vs.com --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!