04 September 2011

Recently I’ve stumbled upon a few brain teasers on C# and it was fun trying to figure out the answers to the problems. So here are a few simple brain teasers from me.

Teaser 1

What will be displayed in the console?

void foo(int a, int b, int c)
{
    Console.WriteLine(a);
    Console.WriteLine(b);
    Console.WriteLine(c);
}

.....

int i = 0;

foo(i++, i++, i++);

Teaser 2

Will that compile?

enum E { A, B, C, }

Teaser 3

How about that:

void foo(string s) {...}

void foo(StringBuilder sb) {...}

....
foo(null);

No answers provided. You want to know the answers, you have to try it yourself, no fun otherwise.

More teasers here and here. Got a brain teaser? Drop a comment.



blog comments powered by Disqus