Click here to Skip to main content
15,922,894 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: C#'s sneaky typedef Pin
johannesnestler7-Jun-13 1:52
johannesnestler7-Jun-13 1:52 
GeneralRe: C#'s sneaky typedef Pin
Chad3F29-May-13 12:49
Chad3F29-May-13 12:49 
GeneralRe: C#'s sneaky typedef Pin
Gary Wheeler4-Jun-13 0:51
Gary Wheeler4-Jun-13 0:51 
RantOh no, not again.... Pin
Lutosław25-May-13 3:23
Lutosław25-May-13 3:23 
GeneralRe: Oh no, not again.... Pin
KP Lee28-May-13 18:11
KP Lee28-May-13 18:11 
GeneralRe: Oh no, not again.... Pin
Lutosław29-May-13 1:12
Lutosław29-May-13 1:12 
GeneralRe: Oh no, not again.... Pin
johannesnestler6-Jun-13 4:32
johannesnestler6-Jun-13 4:32 
GeneralRe: Oh no, not again.... Pin
KP Lee6-Jun-13 20:13
KP Lee6-Jun-13 20:13 
johannesnestler wrote:
I have to ask: You think "readonly" should mean the same like "const"?
Not really, I don't recall talking with the instructor about either const or readonly. And I didn't read anything in the books I'd bought for the training. I just recall seeing it for the first time on the job and my amazement that the values in the readonly object were being changed and the compiler wasn't complaining. Then an "Oh, duh" moment. You can't change the instance, but you can change the contents of the instance. This code is totally legal:
C#
        public class vals
        {
            public int age;
            public DateTime date;
        }
        class x
        {
            public readonly vals val = new vals();
        }
        static void Main(string[] args)
        {
            x val = new x();
            val.val.age = 20;
            val.val.date = DateTime.Now;
...
const has it's own peculiarities, basically it supports value types. When you read the documentation it says the only non-value type is string. I was taught that string was also a value type. I haven't read any documentation (other than const) that contradicts string is a value type. I got an eye opener several years ago when I read that you shouldn't send a string to unmanaged C++ code. Before that, I was totally confused by the statement that strings were IMMUTABLE. I can change the value of the string whenever I want! After I read that article I understood what was meant by that and it makes me believe that you can change a const string variable's value by passing it to that C++ code I mentioned. Much later I learned about Intern and IsInterned.
Because I am not dedicated to this language I don't consider myself near an expert in C#. More knowledgeable than some C# programmers, most dedicated C# developers know more than me.
GeneralRe: Oh no, not again.... Pin
johannesnestler7-Jun-13 2:14
johannesnestler7-Jun-13 2:14 
GeneralRe: Oh no, not again.... Pin
KP Lee7-Jun-13 22:13
KP Lee7-Jun-13 22:13 
GeneralFound something interesting PinPopular
BotCar23-May-13 22:08
BotCar23-May-13 22:08 
GeneralWhy not: // just shoot me! Pin
esaulsberry20-May-13 8:48
esaulsberry20-May-13 8:48 
GeneralRe: Why not: // just shoot me! PinPopular
Pualee20-May-13 10:14
Pualee20-May-13 10:14 
GeneralRe: Why not: // just shoot me! Pin
OriginalGriff20-May-13 11:02
mveOriginalGriff20-May-13 11:02 
GeneralRe: Why not: // just shoot me! Pin
Pankaj Nikam20-May-13 19:26
professionalPankaj Nikam20-May-13 19:26 
GeneralRe: Why not: // just shoot me! Pin
Oshtri Deka20-May-13 22:15
professionalOshtri Deka20-May-13 22:15 
GeneralRe: Why not: // just shoot me! Pin
Gary Wheeler21-May-13 1:17
Gary Wheeler21-May-13 1:17 
GeneralRe: Why not: // just shoot me! Pin
englebart21-May-13 2:39
professionalenglebart21-May-13 2:39 
GeneralRe: Why not: // just shoot me! Pin
Gary Wheeler21-May-13 2:48
Gary Wheeler21-May-13 2:48 
GeneralRe: Why not: // just shoot me! Pin
esaulsberry21-May-13 2:59
esaulsberry21-May-13 2:59 
GeneralRe: Why not: // just shoot me! Pin
agolddog21-May-13 3:35
agolddog21-May-13 3:35 
GeneralRe: Why not: // just shoot me! Pin
esaulsberry21-May-13 3:40
esaulsberry21-May-13 3:40 
GeneralRe: Why not: // just shoot me! Pin
StatementTerminator21-May-13 3:51
StatementTerminator21-May-13 3:51 
GeneralRe: Why not: // just shoot me! Pin
Lutosław24-May-13 0:02
Lutosław24-May-13 0:02 
GeneralRe: Why not: // just shoot me! Pin
StatementTerminator24-May-13 3:49
StatementTerminator24-May-13 3:49 

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

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