|
-
Apr 20th, 2002, 12:07 AM
#1
readonly variable?!!!
I just wrote this and compiler didnt underline it, do we have such a thing!!!?!!
Public ReadOnly curX As Integer
This is in a class. So is that the same as this?
Code:
Public ReadOnly Property CurX() As Integer
Get
Return mCurX
End Get
End Property
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Apr 20th, 2002, 02:15 AM
#2
Yep, it exists. The variable basically becomes a constant.
-
Apr 22nd, 2002, 06:32 AM
#3
It isn't really a constant, because the variable mCurX (assuming is is declared Private) can be changed inside the class. it just can't be changed publicly.
-
Apr 22nd, 2002, 07:04 AM
#4
Originally posted by Frans C
It isn't really a constant, because the variable mCurX (assuming is is declared Private) can be changed inside the class. it just can't be changed publicly.
I'm not sure what you're saying, but this variable:
Public ReadOnly MyInt As Integer
...and this variable:
Private ReadOnly MyInt As Integer
...cannot be changed anywhere, and they are effectively constants. So I'm not sure what you're referring to.
-
Apr 22nd, 2002, 07:10 AM
#5
I was referring to the code example MrPolite posted:
VB Code:
Public ReadOnly Property CurX() As Integer
Get
Return mCurX
End Get
End Property
Assuming the variable mCurX was defined like this:
Private mCurX as Integer
The property CurX is read only, but because this property returns the value of mCurX, it can return variable results, because the variable mCurX can be changed inside the class.
-
Apr 22nd, 2002, 07:20 AM
#6
Originally posted by Frans C
I was referring to the code example MrPolite posted
Oh. I was referring to the ReadOnly variable he was asking about. I believe you misread his post (and therefore mine too). He was asking if ReadOnly variables existed. I believe he already knew about ReadOnly properties. So I was saying that ReadOnly variables (not properties) are effectively constants.
-
Apr 22nd, 2002, 10:54 AM
#7
You're absolutely right tygur, on both accounts.
I misread the question, and ReadOnly variables act like constants.
There are only a few differences between contants and ReadOnly variables.
Next to initializing the variable inline (Public ReadOnly curX As Integer = 5), you can also give it a value in the classes constructor.
VB Code:
Public ReadOnly curX As Integer
Public Sub New()
curX = 6
End Sub
Public Sub New(ByVal NewX As Integer)
curX = Newx
End Sub
ReadOnly variables can be of any type, including reference type variables, where constants can only be Boolean, Byte, Char, Date, Decimal, Double, Integer, Long, Object, Short, Single, String, or the name of an enumeration.
Last edited by Frans C; Apr 22nd, 2002 at 10:58 AM.
-
Apr 22nd, 2002, 01:01 PM
#8
tnx all for the info
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|