Click here to Skip to main content
15,887,175 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: Trick for young players. Pin
BobJanova2-Nov-12 0:50
BobJanova2-Nov-12 0:50 
GeneralRe: Trick for young players. Pin
harold aptroot2-Nov-12 0:25
harold aptroot2-Nov-12 0:25 
GeneralRe: Trick for young players. Pin
englebart2-Nov-12 2:54
professionalenglebart2-Nov-12 2:54 
GeneralRe: Trick for young players. Pin
_Maxxx_4-Nov-12 11:49
professional_Maxxx_4-Nov-12 11:49 
GeneralRe: Trick for young players. Pin
CafedeJamaica2-Nov-12 10:54
professionalCafedeJamaica2-Nov-12 10:54 
GeneralRe: Trick for young players. Pin
AspDotNetDev2-Nov-12 11:28
protectorAspDotNetDev2-Nov-12 11:28 
GeneralRe: Trick for young players. Pin
BotReject4-Nov-12 10:54
BotReject4-Nov-12 10:54 
GeneralRe: Trick for young players. Pin
TheCoolCoder5-Nov-12 1:13
TheCoolCoder5-Nov-12 1:13 
I used this article for reference: link
C#
object arg1 = true;
object arg2 = true;
List<object> collection = new List<object>() { arg1 };

The keyword object doesnt make 'arg1' or 'arg2' a reference type, they are both value types. And as the article clearly states

"If the current instance is a value type, the Equals(Object) method tests for value equality. Value equality means the following:
1.The two objects are of the same type.
2.The values of the public and private fields of the two objects are equal."

when checking
C#
bool first = (collection.Contains(arg1));
bool second = (collection.Contains(arg2));

as both the conditions are satisfied obviously 'Contains' will return true.

As i understand this is exactly the same as doing
C#
int a = 1;
int b = 1;

List<int> intcollection = new List<int>() {a };
bool first = (intcollection.Contains(a));
bool second = (intcollection.Contains(b));
Console.WriteLine(string.Format("{0} {1}", first, second));

in which case we all agree that 'True True' is the output.

I think the confusion occurs because of the tendency to assume object arg1 and object arg2 as reference types. I understand this can cause confusion and bigger underlying problems in a framework scenario but the only reason(AFAIK) causing this is whoever coded it dint realize this beforehand.

but i appreciate this post as I know I would never have come across such a ascenario in years.Please feel free to correct me if I am wrong as I am one of the young players only Smile | :) .
GeneralRe: Trick for young players. Pin
_Maxxx_5-Nov-12 1:40
professional_Maxxx_5-Nov-12 1:40 
GeneralRe: Trick for young players. Pin
Super Lloyd5-Nov-12 17:47
Super Lloyd5-Nov-12 17:47 
GeneralRe: Trick for young players. Pin
_Maxxx_5-Nov-12 22:25
professional_Maxxx_5-Nov-12 22:25 
GeneralSomebody getting paid by the character typed? PinPopular
esaulsberry29-Oct-12 10:17
esaulsberry29-Oct-12 10:17 
GeneralRe: Somebody getting paid by the character typed? Pin
Br.Bill3-Jan-13 12:36
Br.Bill3-Jan-13 12:36 
GeneralThe occasional flash of brilliance Pin
Eddy Vluggen29-Oct-12 9:50
professionalEddy Vluggen29-Oct-12 9:50 
GeneralRe: The occasional flash of brilliance PinPopular
enhzflep29-Oct-12 15:49
enhzflep29-Oct-12 15:49 
GeneralRe: The occasional flash of brilliance PinPopular
CDP180229-Oct-12 19:51
CDP180229-Oct-12 19:51 
GeneralRe: The occasional flash of brilliance Pin
enhzflep29-Oct-12 20:04
enhzflep29-Oct-12 20:04 
GeneralRe: The occasional flash of brilliance PinPopular
CDP180230-Oct-12 1:21
CDP180230-Oct-12 1:21 
GeneralRe: The occasional flash of brilliance Pin
enhzflep30-Oct-12 6:47
enhzflep30-Oct-12 6:47 
GeneralRe: The occasional flash of brilliance Pin
Florin Jurcovici1-Nov-12 0:50
Florin Jurcovici1-Nov-12 0:50 
GeneralRe: The occasional flash of brilliance Pin
Reelix1-Nov-12 1:27
Reelix1-Nov-12 1:27 
GeneralRe: The occasional flash of brilliance Pin
KP Lee1-Nov-12 8:28
KP Lee1-Nov-12 8:28 
GeneralRe: The occasional flash of brilliance Pin
BlackMilan29-Oct-12 22:34
BlackMilan29-Oct-12 22:34 
GeneralRe: The occasional flash of brilliance Pin
Dan Neely1-Nov-12 2:41
Dan Neely1-Nov-12 2:41 
GeneralRe: The occasional flash of brilliance Pin
Sasha Laurel1-Nov-12 4:34
Sasha Laurel1-Nov-12 4:34 

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.