Click here to Skip to main content
15,910,277 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
JokeRe: Oi! pkfox! Where's the CCC? Pin
Randor 1-Jun-18 1:03
professional Randor 1-Jun-18 1:03 
GeneralCommitStrip OTD PinPopular
OriginalGriff31-May-18 20:49
mveOriginalGriff31-May-18 20:49 
GeneralRe: CommitStrip OTD Pin
Johnny J.31-May-18 21:49
professionalJohnny J.31-May-18 21:49 
GeneralSo I Bought Them Pin
Michael Martin31-May-18 19:36
professionalMichael Martin31-May-18 19:36 
GeneralRe: So I Bought Them Pin
dan!sh 31-May-18 23:53
professional dan!sh 31-May-18 23:53 
GeneralRe: So I Bought Them Pin
Michael Martin1-Jun-18 5:14
professionalMichael Martin1-Jun-18 5:14 
GeneralRe: So I Bought Them Pin
dan!sh 3-Jun-18 17:41
professional dan!sh 3-Jun-18 17:41 
GeneralCode Puzzler: How quickly can you figure out why this acting "weird"? Pin
Marc Clifton31-May-18 7:56
mvaMarc Clifton31-May-18 7:56 
And no, this isn't a programming question in the lounge. I started asking this question in the QA forum because it had me totally stumped. As I was filling out the "What I've tried" I had a major D'Oh! | :doh: D'Oh! | :doh: D'Oh! | :doh: D'Oh! | :doh: moment.

To prove I'm not asking for help on the lounge, I posted a solution on my blog. You'll need to use the password "fizbin" as the blog post is specifically for this lounge post and eventually I'll delete the post.

It is a fun one though.

Here's the code:
public class ModelDataContext : DataContext
{
    public static ModelDataContext Context;

    public ModelDataContext(DbConnection conn) : base(conn)
    {
        Context = this;
    }
}

class Program
{
    static ModelDataContext mdc = new ModelDataContext(new SqlConnection("[some string]"));

    static void CreateNewContext(DataContext context, out SqlConnection conn, out DataContext newContext)
    {
        conn = new SqlConnection(context.Connection.ConnectionString);
        newContext = (DataContext)Activator.CreateInstance(context.GetType(), new object[] { conn });
        Console.WriteLine(context == newContext);
    }

    static void Main(string[] args)
    {
        SqlConnection conn2;
        DataContext newdc;
        CreateNewContext(ModelDataContext.Context, out conn2, out newdc);

        Console.WriteLine(ModelDataContext.Context == newdc);
    }
}

and the result is:

False
True

Why is the second equality True when the first is False???

And for the bonus prize, what's a fix?
Latest Article - Building a Prototype Web-Based Diagramming Tool with SVG and Javascript

Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

Artificial intelligence is the only remedy for natural stupidity. - CDP1802

GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
User 1106097931-May-18 9:07
User 1106097931-May-18 9:07 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Marc Clifton31-May-18 9:14
mvaMarc Clifton31-May-18 9:14 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
User 1106097931-May-18 9:22
User 1106097931-May-18 9:22 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
OriginalGriff31-May-18 10:00
mveOriginalGriff31-May-18 10:00 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Mike Hankey31-May-18 14:29
mveMike Hankey31-May-18 14:29 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
OriginalGriff31-May-18 22:18
mveOriginalGriff31-May-18 22:18 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Mike Hankey1-Jun-18 1:26
mveMike Hankey1-Jun-18 1:26 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Member 115770084-Jun-18 3:23
Member 115770084-Jun-18 3:23 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Richard Deeming31-May-18 9:58
mveRichard Deeming31-May-18 9:58 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Marc Clifton31-May-18 10:43
mvaMarc Clifton31-May-18 10:43 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
PIEBALDconsult31-May-18 10:13
mvePIEBALDconsult31-May-18 10:13 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Jon McKee31-May-18 10:17
professionalJon McKee31-May-18 10:17 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Richard Deeming31-May-18 10:19
mveRichard Deeming31-May-18 10:19 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Jon McKee31-May-18 10:22
professionalJon McKee31-May-18 10:22 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Richard Deeming31-May-18 10:42
mveRichard Deeming31-May-18 10:42 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Marc Clifton31-May-18 10:48
mvaMarc Clifton31-May-18 10:48 
GeneralRe: Code Puzzler: How quickly can you figure out why this acting "weird"? Pin
Richard Deeming31-May-18 11:01
mveRichard Deeming31-May-18 11:01 

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.