-
August 16th, 2010, 04:52 PM
#1
Why wont my enum be what it is ? I have to cast it to get the number
I dont use enums or c# much but i thought they were to represent lists of numbers as actual values so your code could look nicer, similar to #define in c
anyway i'm doin this , because i dont want to have/remember these values all the time
public enum txMask : byte
{
battery = 0x01,
accel = 0x02,
sonar = 0x04,
line = 0x08, //1000
gps = 0x10, //10000
move = 0x20, //100000
test = 0x33
}
and then i try and use it in this function that accepts a byte
setTXFlag(txMask.test);
and i get the error
Error 1 The best overloaded method match for 'JinxDebug.comm.setTXFlag(byte)' has some invalid arguments N:\SeniorProj\HighLevel\JinxDebug\JinxDebug\comm.cs 64 13 JinxDebug
Error 2 Argument '1': cannot convert from 'JinxDebug.comm.txMask' to 'byte' N:\SeniorProj\HighLevel\JinxDebug\JinxDebug\comm.cs 64 23 JinxDebug
but if i cast it like this
setTXFlag((byte)txMask.test);
it works great ... ??
How can i avoid casting my enums all the time or should I be doing this another way ... I have quite a few enums that are very useful but assigning them ":int" and then still having to cast them seems dumb (I'm talking about another enum, that even though the "default" is int it still needs to be casted as int).
thanks for your time
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
|