473,382 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Enum Question

I have an enum defined as
public enum WineType
{
Bubbly,
Dessert,
Pink,
Red,
White
};

In the codebehind of a webform, I'm doing this:

switch ((WineType) drBottle["Type"])
{
// do something ...

drBottle["Type"] would come in as "Bubbly" or "Dessert", etc...

This compiles but I get an invalid Cast exception when the webform loads.

How do I cast this properly?
Nov 18 '05 #1
2 897
Use the Enum.Parse method

Tu-Thac
www.ongtech.co

----- George Durzi wrote: ----

I have an enum defined a
public enum WineTyp

Bubbly
Dessert
Pink
Red
Whit
}

In the codebehind of a webform, I'm doing this

switch ((WineType) drBottle["Type"]

// do something ..

drBottle["Type"] would come in as "Bubbly" or "Dessert", etc..

This compiles but I get an invalid Cast exception when the webform loads

How do I cast this properly

Nov 18 '05 #2
Thank you, that worked.

"Tu-Thach" <an*******@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
Use the Enum.Parse method.

Tu-Thach
www.ongtech.com

----- George Durzi wrote: -----

I have an enum defined as
public enum WineType
{
Bubbly,
Dessert,
Pink,
Red,
White
};

In the codebehind of a webform, I'm doing this:

switch ((WineType) drBottle["Type"])
{
// do something ...

drBottle["Type"] would come in as "Bubbly" or "Dessert", etc...

This compiles but I get an invalid Cast exception when the webform loads.
How do I cast this properly?

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
10
by: James Brown | last post by:
I have the following enum declared: enum TOKEN { TOK_ID = 1000, TOK_NUMBER, TOK_STRING }; (it goes on and on like that) This is what I would like to do: TOKEN t1 = TOK_ID; // ok...
4
by: Nikhil Patel | last post by:
Hi all, I am a VB6 programmer and learning C#. I am currently reading a chapter on types. I have question regarding enums. Why do we need to convert enum members to the value that they represent?...
5
by: Andrea Williams | last post by:
I'm working with C# and I'm setting up some ENUM's I have a data and Business layer. I'm declaring a common enum for the Data Layer. The UI layer references the Bus layer and the bus layer...
6
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I...
2
by: Dennis | last post by:
I have an enum as follows: Public Enum myData FirstData = 6 SecondData = 7 end enum Is there anyway that I can return the Enum names by their value, i.e., I want to input 6 into a function...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
3
by: K. Wilder | last post by:
I need to declare a project level Enum that any procedure in any class can reference so there's continuity with the values. How do I do this? At present, if I declare a Module in a project and...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
4
by: ice8595 | last post by:
Hi there, I'm fairly new at this, and I am having a bit of trouble wrapping my head around some concepts of enum for a project. So any help would be greatly appreciated. Essentially I'm...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.