Newbie...
I'm casting enums back and forth to ints so to use them as an index into a
complex two dimensional array. I thought it would help readability.
Instead, my code has casts all over the place.
All the casting is giving me the jitters. Where did I go wrong?
Thanks! 4 2085
Why are you casting them in the first place? :)
public enum ConnectionStatus : int
{
Resolving, Resolved, Connecting, Connected, Disconnecting, Disconnected
}
ShaneB
"Craig" <sp******@hotmail.com> wrote in message
news:Xv*******************@twister.socal.rr.com... Newbie...
I'm casting enums back and forth to ints so to use them as an index into a complex two dimensional array. I thought it would help readability. Instead, my code has casts all over the place.
All the casting is giving me the jitters. Where did I go wrong?
Thanks!
ShaneB,
There is no implicit cast for enums to their underlaying type. public enum ConnectionStatus : int { Resolving, Resolved, Connecting, Connected, Disconnecting, Disconnected }
In fact, despite of the that syntax c# uses, ConnectionStatus doesn't
inherit from *int*
Thus, in the case of using enum values for indexing arrays casting is
necessary.
--
Stoitcho Goutsev (100) [C# MVP]
"ShaneB" <st********@yahoo.com> wrote in message
news:ev**************@TK2MSFTNGP11.phx.gbl... Why are you casting them in the first place? :)
public enum ConnectionStatus : int { Resolving, Resolved, Connecting, Connected, Disconnecting, Disconnected } ShaneB
"Craig" <sp******@hotmail.com> wrote in message news:Xv*******************@twister.socal.rr.com... Newbie...
I'm casting enums back and forth to ints so to use them as an index into a complex two dimensional array. I thought it would help readability. Instead, my code has casts all over the place.
All the casting is giving me the jitters. Where did I go wrong?
Thanks!
Actually, that post should have been canceled. Two seconds after I hit
send, I realized my mistake :)
ShaneB
"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:uf**************@tk2msftngp13.phx.gbl... ShaneB,
There is no implicit cast for enums to their underlaying type.
public enum ConnectionStatus : int { Resolving, Resolved, Connecting, Connected, Disconnecting, Disconnected }
In fact, despite of the that syntax c# uses, ConnectionStatus doesn't inherit from *int*
Thus, in the case of using enum values for indexing arrays casting is necessary.
Craig wrote: Newbie...
I'm casting enums back and forth to ints so to use them as an index into a complex two dimensional array. I thought it would help readability. Instead, my code has casts all over the place.
All the casting is giving me the jitters. Where did I go wrong?
Thanks!
How about using constants instead of enum values?
* same readability of enum (words instead of "magic numbers")
* they really are int's
public const int WHATEVER = 3;
myval = store[WHATEVER];
Hans Kesting This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark A. Gibbs |
last post by:
i have been toying with the idea of making my enums smarter - ie, more
in line with the rest of the language. i haven't tested it yet, but what
i came up with is a template like this:
template...
|
by: Jarmo Muukka |
last post by:
Hello all!
I have used C++ for many years and recently I have used C#. Now I am coding
in C++ and I have a problem now.
In C# you can do enums like this:
enum Lane
{
Left,
|
by: mdh |
last post by:
In one of the answers to a K&R exercise, the first couple of lines are:
enum loop { NO, YES};
enum loop okloop=YES;
I get the first line, but not the second.
Sorry about the LOL question.
...
|
by: Bob |
last post by:
Hi,
Can someone explain why you can't declare enums in an interface?
The compiler says "interfaces can't declare types"
Ignoring the syntax implications it seems to me that you should be able to...
|
by: =?Utf-8?B?Sm9uYXRoYW4gU21pdGg=?= |
last post by:
I have a class as follows:
class GamesConsole
{
public int iReference;
public enum Maker {Nintendo, Sega, Sony, Panasonic}
}
|
by: olympus_mons |
last post by:
Hi,
I'm just discovering the power of xsd.exe, so maybe I'm doing
something wrong.
schema files describing requests and responses. So there is an extra
xsd file for each response and each...
|
by: Zytan |
last post by:
I know you can use enums as a bit field with , but,
when I use an enum without , I can still combine one
or more of them. There's no error in doing so. I thought enums were
strongly typed, such...
|
by: Ian Semmel |
last post by:
If I have
Enum en
{
i1,
i2,
i3
}
I reckon I should be able to have
|
by: Daniel Gutson |
last post by:
Hi,
I just wanted to share another library for doing type-safe bitwise
operations in C++:
http://bitwise-enum.googlecode.com
I found it useful, so hopefully it'll be for somebody else as well....
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
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...
|
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...
| |