473,322 Members | 1,755 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,322 software developers and data experts.

Problem with GetValues on Enum type

Hi Folks,

I've tried to do the following:
public enum AssetType { Requested, InOrder, Received, InPlace, Gone };
(...)
dropAssetType.DataSource = Enum.GetValues(AssetType);
(...)

For some reason this get get compiled, since it says that AssetType is a
class, while a variable is expected,

Any suggestions woulde be appreciated!

Greets,

Gab

Nov 16 '05 #1
6 2256
Hi Gabriël,

Change your code to

dropAssetType.DataSource = Enum.GetValues(typeof(AssetType));

Not exactly sure why just passing AssetType won't work, maybe someone can
clarify.

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Morten Wennevik <Mo************@hotmail.com> wrote:
Change your code to

dropAssetType.DataSource = Enum.GetValues(typeof(AssetType));

Not exactly sure why just passing AssetType won't work, maybe someone can
clarify.


Because AssetType isn't an expression - it's the name of a type.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Um, you mean it isn't a type, just a name?
Well, I suppose, since GetValues requires a type, but somehow I would
expect it to work by passing enum name, and have GetValues handle the
typeof cast internally if needed.

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4
Morten Wennevik <Mo************@hotmail.com> wrote:
Um, you mean it isn't a type, just a name?
Just "AssetType" isn't an expression. typeof(AssetType) is an
expression. AssetType is a type token in terms of the C# language
specification - but it certainly isn't an expression. If you think it's
an expression, what's its value?
Well, I suppose, since GetValues requires a type, but somehow I would
expect it to work by passing enum name, and have GetValues handle the
typeof cast internally if needed.


typeof isn't a cast - it's an operator.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

But now that the Whidbey compiler lets you specify just a method name
where a delegate is expected (and the compiler figures out the correct
delegate type and adds the instantiation code), you could argue that
you should also be able to specify just a typename in places where a
Type is expected. Just a thought.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #6
Thanks for all the advices (and explaination, which makes also the why
clear, next tot the how).

Gab

"Mattias Sjögren" <ma********************@mvps.org> schreef in bericht
news:u#**************@TK2MSFTNGP10.phx.gbl...

But now that the Whidbey compiler lets you specify just a method name
where a delegate is expected (and the compiler figures out the correct
delegate type and adds the instantiation code), you could argue that
you should also be able to specify just a typename in places where a
Type is expected. Just a thought.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 16 '05 #7

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

Similar topics

3
by: Tim Mulholland | last post by:
I am having a problem where a color i select, and convert to a string for storage in an XML file is not being converted back properly. The following is a small example that illustrates the...
2
by: smith | last post by:
It's a time saver to "bind" .Net enums to list and comboboxes and all the samples out there seem to use GetNames and GetValues pretty interchangeably. So I was wondering what the logic is to the...
9
by: thechaosengine | last post by:
Hi all, I have a problem that I havent really come accross before. I need to be able to allow the user to set a dropdown control to a particular colour value. The permissable values come from...
2
by: Armin Bajramovic | last post by:
Hi, I have enum: public enum StatusEnum { Active = 'A', Nonactive = 'N', Deleted = 'D' }
4
by: George | last post by:
I am trying to check whether a query string is being passed to my .aspx page, like so: If Not Request.QueryString Is Nothing Then If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then...
9
by: Mircea | last post by:
Hi everybody, I have a big problem. I am trying to use serial communication in C# 2. The problem is that the event DataReceived is never fired. I have tried on two computers and it does not...
8
by: tony | last post by:
Hello! I have below a for loop and a switch in the for loop. I have also a enum called colBlowStep with some values. I have also an array called m_columnBlowStep with some strings. All items in...
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...
1
by: Jeff Mason | last post by:
I am observing some puzzling behavior with the GetValues method of enumerations. I wonder if this something I just don't understand, or is this just wrong. The documentation for the GetValues...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.