|
-
Sep 23rd, 2003, 05:33 PM
#1
Thread Starter
Member
Resolved: Data Type
Not sure if this can be done, but I would think that you could. Basically what I'm wanting to know is if you are creating a new object, is there a way to create a new data type for one of the properties? I'll try to give a simple example. If I wanted one property to be "Gender" is there a way to create a data type that allows only the "Female" and "Male" options for that property, like "True" and "False" with other properties? Hopefully that makes sense.
Thanks in advance!
Last edited by Cmathis; Sep 24th, 2003 at 09:57 AM.
-
Sep 23rd, 2003, 05:40 PM
#2
yay gay
i really didnt get it
you want to create a class/struct that has an enum saying Woman, Man?
\m/  \m/
-
Sep 23rd, 2003, 05:45 PM
#3
Thread Starter
Member
In a simple fashion, yes. I was just giving that as an example. I want to be able to do something like this:
Human.Gender = "Male"
or
Human.Gender = "Female"
-
Sep 23rd, 2003, 06:06 PM
#4
Use an Enum:
VB Code:
Public Class Human
Public Enum Genders
Male
Female
End Enum
Private _Gender As Genders
Public Property Gender() As Genders
Get
Return _Gender
End Get
Set(ByVal Value As Genders)
_Gender = Value
End Set
End Property
End Class
'syntax
Dim you As New Human
you.Gender=Male
-
Sep 24th, 2003, 08:51 AM
#5
Thread Starter
Member
That works fine, but now I have one more question. If you have a string now that is "Male", can that be casted to the Genders type instead of being a string?
-
Sep 24th, 2003, 09:43 AM
#6
Yes.
VB Code:
Dim you As New Human
you.Gender=[Enum].Parse(gettype(Genders),"Male")
-
Sep 24th, 2003, 09:57 AM
#7
Thread Starter
Member
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
|