Click here to Skip to main content
11,649,546 members (78,179 online)

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy except programming questions.

Technical discussions are encouraged, but click here to ask your programming question.

The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct, no programming questions and please don't post ads.
 
GeneralRe: Job Interview completed. Pin
SoMad20-Mar-13 19:17
memberSoMad20-Mar-13 19:17 
GeneralRe: Job Interview completed. Pin
AspDotNetDev20-Mar-13 19:29
protectorAspDotNetDev20-Mar-13 19:29 
GeneralRe: Job Interview completed. Pin
Tadit Dash20-Mar-13 20:13
memberTadit Dash20-Mar-13 20:13 
GeneralRe: Job Interview completed. Pin
Edo Tzumer20-Mar-13 21:57
memberEdo Tzumer20-Mar-13 21:57 
GeneralRe: Job Interview completed. Pin
PHS24120-Mar-13 23:02
memberPHS24120-Mar-13 23:02 
GeneralRe: Job Interview completed. Pin
Pete O'Hanlon21-Mar-13 1:15
protectorPete O'Hanlon21-Mar-13 1:15 
NewsThis explains that last meeting I was in Pin
Kent Sharkey20-Mar-13 15:33
memberKent Sharkey20-Mar-13 15:33 
GeneralRe: This explains that last meeting I was in Pin
ThePhantomUpvoter20-Mar-13 16:38
memberThePhantomUpvoter20-Mar-13 16:38 
GeneralRe: This explains that last meeting I was in Pin
wizardzz20-Mar-13 17:11
memberwizardzz20-Mar-13 17:11 
GeneralRe: This explains that last meeting I was in Pin
Paul Watt20-Mar-13 18:02
mentorPaul Watt20-Mar-13 18:02 
GeneralRe: This explains that last meeting I was in Pin
lewax0020-Mar-13 18:43
memberlewax0020-Mar-13 18:43 
GeneralRe: This explains that last meeting I was in Pin
Michael Martin 20-Mar-13 23:05
member Michael Martin 20-Mar-13 23:05 
GeneralRe: This explains that last meeting I was in Pin
Mark_Wallace20-Mar-13 23:22
memberMark_Wallace20-Mar-13 23:22 
GeneralDoes this language feature seem strange to anyone else? Pin
lewax0020-Mar-13 12:58
memberlewax0020-Mar-13 12:58 
Part of an application I work on involves navigation through a series of documents, previously the navigate function looked like:
void NavigateTo(int document)
but as part of a redesign that made a single numeric index lose it's meaning, I changed it to
void NavigateTo(NavigationDirection direction)
where NavigationDirection is an enum consisting of Forward and Backward. As expected, the change caused some compilation errors where it was being called, because C# doesn't allow implicit conversion of int to enum. Having written the section of code it was in, I was pretty sure I knew where all the calls were, and the compiler seemed to agree...but the navigation was acting funny, it started at the second document. Debugged it, and found a third call to the function, that looked like this:
NavigateTo(0);
and 0 was the value of Forward, which was then moving it to the 2nd document, added a third value to the enum, None, since the first document was already being loaded in a new way, and this was just moving past it (the navigation has some side effects, loading other things related to the document, so the call was still needed...it makes more sense in the actual code, I'm just simplifying it). But hold on, I thought there wasn't an implicit conversion from int to enum types in C#?

So I played around with it a bit, and here's what I discovered: ints are not implicitly convertible to enum types (as I thought)...but const ints are 0 is! Both integer literals, and const int variables, as long as the value maps to a value in the enum (if it had been a number greater than 1 other than 0, I would have had the expected compiler error). While I understand how the compiler can implement this, I don't understand why they would, it seems to go against the C# language itself. I don't think you could even write your own implicit conversion that behaves the same way, since from what I can tell C# doesn't generally make a distinction between const and non-const versions of the same type for the purposes of parameters (e.g. int and const int can be used interchangeably), with the exception of ref and out...but that causes restriction in the reverse direction (only non-const).

Seems like an odd language design choice to me D'Oh! | :doh:

EDIT: looks like I jumped the gun a little on this one, apparently, it only works for 0. Which is probably worse...
GeneralRe: Does this language feature seem strange to anyone else? Pin
PIEBALDconsult20-Mar-13 13:43
memberPIEBALDconsult20-Mar-13 13:43 
GeneralRe: Does this language feature seem strange to anyone else? Pin
lewax0020-Mar-13 14:00
memberlewax0020-Mar-13 14:00 
GeneralRe: Does this language feature seem strange to anyone else? Pin
AspDotNetDev20-Mar-13 14:04
protectorAspDotNetDev20-Mar-13 14:04 
GeneralRe: Does this language feature seem strange to anyone else? Pin
lewax0020-Mar-13 14:11
memberlewax0020-Mar-13 14:11 
GeneralRe: Does this language feature seem strange to anyone else? Pin
PIEBALDconsult20-Mar-13 14:17
memberPIEBALDconsult20-Mar-13 14:17 
GeneralRe: Does this language feature seem strange to anyone else? Pin
Matthew Faithfull20-Mar-13 14:10
memberMatthew Faithfull20-Mar-13 14:10 
GeneralRe: Does this language feature seem strange to anyone else? Pin
lewax0020-Mar-13 14:13
memberlewax0020-Mar-13 14:13 
GeneralRe: Does this language feature seem strange to anyone else? Pin
Matthew Faithfull20-Mar-13 14:29
memberMatthew Faithfull20-Mar-13 14:29 
GeneralRe: Does this language feature seem strange to anyone else? Pin
lewax0020-Mar-13 14:39
memberlewax0020-Mar-13 14:39 
GeneralRe: Does this language feature seem strange to anyone else? Pin
Matthew Faithfull20-Mar-13 15:10
memberMatthew Faithfull20-Mar-13 15:10 
GeneralRe: Does this language feature seem strange to anyone else? Pin
Mike Winiberg21-Mar-13 22:14
memberMike Winiberg21-Mar-13 22:14 
GeneralRe: Does this language feature seem strange to anyone else? Pin
AspDotNetDev20-Mar-13 13:56
protectorAspDotNetDev20-Mar-13 13:56 
GeneralRe: Does this language feature seem strange to anyone else? Pin
lewax0020-Mar-13 14:06
memberlewax0020-Mar-13 14:06 
GeneralRe: Does this language feature seem strange to anyone else? Pin
AspDotNetDev20-Mar-13 14:09
protectorAspDotNetDev20-Mar-13 14:09 
GeneralRe: Does this language feature seem strange to anyone else? Pin
jschell21-Mar-13 10:04
memberjschell21-Mar-13 10:04 
GeneralRe: Does this language feature seem strange to anyone else? Pin
lewax0021-Mar-13 10:27
memberlewax0021-Mar-13 10:27 
GeneralRe: Does this language feature seem strange to anyone else? Pin
César de Souza22-Mar-13 0:43
memberCésar de Souza22-Mar-13 0:43 
GeneralRe: Does this language feature seem strange to anyone else? Pin
lewax0022-Mar-13 10:58
memberlewax0022-Mar-13 10:58 
GeneralRe: Does this language feature seem strange to anyone else? Pin
englebart22-Mar-13 2:26
memberenglebart22-Mar-13 2:26 
GeneralRe: Does this language feature seem strange to anyone else? Pin
lewax0022-Mar-13 10:41
memberlewax0022-Mar-13 10:41 
GeneralRe: Does this language feature seem strange to anyone else? Pin
RafagaX22-Mar-13 6:40
memberRafagaX22-Mar-13 6:40 
GeneralRe: Does this language feature seem strange to anyone else? Pin
Chadwick Posey22-Mar-13 7:48
memberChadwick Posey22-Mar-13 7:48 
GeneralRe: Does this language feature seem strange to anyone else? Pin
lewax0022-Mar-13 10:45
memberlewax0022-Mar-13 10:45 
GeneralReading Code Pin
Kyudos20-Mar-13 11:22
memberKyudos20-Mar-13 11:22 
GeneralRe: Reading Code Pin
wizardzz20-Mar-13 11:29
memberwizardzz20-Mar-13 11:29 
GeneralRe: Reading Code Pin
AspDotNetDev20-Mar-13 11:40
protectorAspDotNetDev20-Mar-13 11:40 
JokeRe: Reading Code Pin
Kyudos20-Mar-13 11:47
memberKyudos20-Mar-13 11:47 
GeneralRe: Reading Code Pin
lewax0020-Mar-13 11:42
memberlewax0020-Mar-13 11:42 
GeneralRe: Reading Code Pin
CDP180220-Mar-13 11:39
memberCDP180220-Mar-13 11:39 
GeneralRe: Reading Code Pin
dusty_dex20-Mar-13 11:45
memberdusty_dex20-Mar-13 11:45 
JokeRe: Reading Code Pin
Kyudos20-Mar-13 11:48
memberKyudos20-Mar-13 11:48 
GeneralRe: Reading Code Pin
PIEBALDconsult20-Mar-13 12:50
memberPIEBALDconsult20-Mar-13 12:50 
GeneralRe: Reading Code Pin
Rob Grainger22-Mar-13 3:00
memberRob Grainger22-Mar-13 3:00 
GeneralRe: Reading Code Pin
Eddy Vluggen20-Mar-13 12:45
mvpEddy Vluggen20-Mar-13 12:45 
GeneralRe: Reading Code Pin
_Josh_20-Mar-13 13:31
member_Josh_20-Mar-13 13:31 
GeneralRe: Reading Code Pin
PIEBALDconsult20-Mar-13 13:35
memberPIEBALDconsult20-Mar-13 13:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.150804.4 | Last Updated 5 Aug 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid