just a question about classes
I'm making a class and I will be making about 30 objects from that class. Would it be bad to declare all the constants of my class as shared? like this:
Code:
Public Class FFUser
Shared ReadOnly TAG_ADMIN As String = "isAdmin"
Shared ReadOnly TAG_USERNAME As String = "UserName"
....
Public Function ...
End Class
I was just thinking that this would save some memory if I create 30 or more instances of this class
Am I wrong:rolleyes:
thanks in advance
Gotta clear a few things up..
Constants are not the same thing as ReadOnly variables. After rereading posts, I found that the original question was about readonly variables, Candor's reply was for constants, and I replied to Candor's post, assuming that the was talking about readonly variables (which still might've been his intention). Then Dilenger4 popped in with one almost true statement and then some stuff that confused me in his second post.
Here are the facts:
ReadOnly variables can be set from within the constructor of the class, and nowhere else. If this ReadOnly variable is Shared, then the constructor with the code that sets it must also be Shared. By the way, this shared constructor will only run once, instead of every time a new instance is created. Unlike with the Java final keyword, you can set the ReadOnly variable as many times as you like, as long as you're doing it within a constructor of the class. ReadOnly variables are very different from constants, which cannot be set from anywhere at all.
Re: Gotta clear a few things up..
Quote:
Originally posted by Tygur
Constants are not the same thing as ReadOnly variables. After rereading posts, I found that the original question was about readonly variables, Candor's reply was for constants, and I replied to Candor's post, assuming that the was talking about readonly variables (which still might've been his intention). Then Dilenger4 popped in with one almost true statement and then some stuff that confused me in his second post.
well he did mention contants in his original post which is what I was going by. My reply was mostly a guess as I havent used shared yet and havent read much about it. Seems like I was fairly close though! :)
So much new stuff to learn. Got three, very thick .NET books to finish reading! :P