Hey,
I think the ToString() would do the trick for you. Hope I got what you were
asking for right, anyways check this out:
Public Class statesConverted
Public Enum states
value1
value2
value3
value4
End Enum
Public value As states
Public Sub New(ByVal val As states)
value = val
End Sub
Public Shared Widening Operator CType(ByVal variable As
statesConverted) As String
Select Case variable.value
Case states.value1
Return "This is value 1"
Case Else
Return "Other values"
End Select
End Operator
Public Overrides Function ToString() As String
Select Case Me.value
Case states.value1
Return "This is value 1"
Case states.value2
Return "This is value 2"
Case states.value3
Return "This is value 3"
Case states.value4
Return "This is value 4"
Case Else
Throw New
System.ComponentModel.InvalidEnumArgumentException("Invalid Enum value
passed")
End Select
End Function
End Class
Public Sub main()
Dim newVariable As New
statesConverted(statesConverted.states.value1)
'MsgBox(newVariable) 'will work
'MsgBox(newVariable.value) 'still won't do what you want
MsgBox(newVariable.ToString) ' maybe this is what you are asking
for?
End Sub
Regards,
Kaarthik
On Sun, Nov 30, 2008 at 2:39 AM, thomat65 <[EMAIL PROTECTED]> wrote:
>
> That's what I was afraid of. I suppose that I'll just settle for
> something slightly less than exactly what I wanted.
>
> On Nov 28, 8:27 pm, "Brandon Betances" <[EMAIL PROTECTED]> wrote:
> > OK C, i tried it and your right, should've remembered enums don't have
> > anything to do with strings. But I don't understand why this wouldnt be
> > sufficient enough:
> >
> > enum States { AK, AL, AR, AZ ... }
> >
> > States state = state.AK
> > Console.WriteLine("you've selected " + state);
> >
> > Now, if your looking to translate AK to a string that prints "Alaska",
> then
> > I dont think an enum is the right thing to handle this type of operation.
>