473,396 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C# teasers

Hi,
I'm looking for C# brain teasers (or VB.NET): a little piece of code
that does something special, or where a little error is. Does anyone
has some of these, or links to sites?
Thanks!
Nov 27 '07 #1
16 2661
On Nov 27, 1:14 pm, Ludwig <lstuyc...@gmail.comwrote:
I'm looking for C# brain teasers (or VB.NET): a little piece of code
that does something special, or where a little error is. Does anyone
has some of these, or links to sites?
Are you after "this doesn't do what you think it does" type things (eg
overloading special cases, or captured variables) or "you should be
able to get this really" questions?

Jon
Nov 27 '07 #2
Hello Ludwig,

Use the MS certification preparation matherials for this.
They are a good source for such kind of teasers

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
LHi,
LI'm looking for C# brain teasers (or VB.NET): a little piece of code
Lthat does something special, or where a little error is. Does anyone
Lhas some of these, or links to sites?
LThanks!
Nov 27 '07 #3
On 27 nov, 15:01, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Nov 27, 1:14 pm, Ludwig <lstuyc...@gmail.comwrote:
I'm looking for C# brain teasers (or VB.NET): a little piece of code
that does something special, or where a little error is. Does anyone
has some of these, or links to sites?

Are you after "this doesn't do what you think it does" type things (eg
overloading special cases, or captured variables) or "you should be
able to get this really" questions?

Jon
Both :)
Nov 27 '07 #4
On Nov 27, 2:33 pm, Ludwig <lstuyc...@gmail.comwrote:

<snip>
Both :)
Okay. I've a few ideas - I'll post some tonight.

Jon
Nov 27 '07 #5
On 27 nov, 15:41, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Nov 27, 2:33 pm, Ludwig <lstuyc...@gmail.comwrote:

<snip>
Both :)

Okay. I've a few ideas - I'll post some tonight.

Jon
Thank you! Meanwhile I'm looking into the certification books - I've
to take the exams anyway, so it's a good waste of time ;)
Nov 27 '07 #6


"Ludwig" wrote:
Hi,
I'm looking for C# brain teasers (or VB.NET): a little piece of code
that does something special, or where a little error is. Does anyone
has some of these, or links to sites?
Thanks!
Nov 27 '07 #7
I have a program that finds prime numbers, if you are interested.

"Ludwig" wrote:
Hi,
I'm looking for C# brain teasers (or VB.NET): a little piece of code
that does something special, or where a little error is. Does anyone
has some of these, or links to sites?
Thanks!
Nov 27 '07 #8
There's one here that threw me for a loop late one night:

http://groups.google.com/group/micro...4fc9ba3b43ae3b

Other fun ones include some of Joe Duffy's (and Jon Skeet's) examples of
broken double-check locks.

--
Chris Mullins

"Ludwig" <ls*******@gmail.comwrote in message
news:11**********************************@s12g2000 prg.googlegroups.com...
Hi,
I'm looking for C# brain teasers (or VB.NET): a little piece of code
that does something special, or where a little error is. Does anyone
has some of these, or links to sites?
Thanks!

Nov 27 '07 #9
x = x & (x-1)
"Ludwig" <ls*******@gmail.comwrote in message
news:11**********************************@s12g2000 prg.googlegroups.com...
Hi,
I'm looking for C# brain teasers (or VB.NET): a little piece of code
that does something special, or where a little error is. Does anyone
has some of these, or links to sites?
Thanks!

Nov 27 '07 #10
Ludwig wrote:
Hi,
I'm looking for C# brain teasers (or VB.NET): a little piece of code
that does something special, or where a little error is. Does anyone
has some of these, or links to sites?
Special? How about this:

Why does this compile:

public class Program{
public static void Main(string[] args){
TypedReference typedReference = new TypedReference();
}
}

and this not compile:

public class Program{
public static void Main(string[] args){
object typedReference = new TypedReference();
}
}

Alun Harford
Nov 27 '07 #11
Ludwig <ls*******@gmail.comwrote:

<snip>
Thank you! Meanwhile I'm looking into the certification books - I've
to take the exams anyway, so it's a good waste of time ;)
Here are some to be going on with. I'll add to the list as I remember
them...

http://pobox.com/~skeet/csharp/teasers.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Nov 27 '07 #12
On Nov 27, 2:46 pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
Here are some to be going on with. I'll add to the list as I remember
them...

http://pobox.com/~skeet/csharp/teasers.html

--

I love #2. I've seen your blog about beforefieldinit before. It
would be plain wrong to ask somebody that question in an interview :)

By the way, you should keep adding to that page periodically or as you
run across a good one.
Nov 27 '07 #13
On Nov 27, 7:14 am, Ludwig <lstuyc...@gmail.comwrote:
Hi,
I'm looking for C# brain teasers (or VB.NET): a little piece of code
that does something special, or where a little error is. Does anyone
has some of these, or links to sites?
Thanks!
This one piqued my interest some time back.

http://groups.google.com/group/micro...0965d37f201ddb
Nov 27 '07 #14
Brian Gideon <br*********@yahoo.comwrote:
I love #2. I've seen your blog about beforefieldinit before. It
would be plain wrong to ask somebody that question in an interview :)
Indeed. Unless they were claiming to know absolutely everything about
C#, in which case anything is fair game.
By the way, you should keep adding to that page periodically or as you
run across a good one.
Absolutely - I've been meaning to do something like it for a while.
This thread was a catalyst :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Nov 27 '07 #15
On 27 nov, 21:46, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
Ludwig <lstuyc...@gmail.comwrote:

<snip>
Thank you! Meanwhile I'm looking into the certification books - I've
to take the exams anyway, so it's a good waste of time ;)

Here are some to be going on with. I'll add to the list as I remember
them...

http://pobox.com/~skeet/csharp/teasers.html

--
Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
World class .NET training in the UK:http://iterativetraining.co.uk
Perfect, I've bookmarked your site and will have a look!! Thanks!
Nov 28 '07 #16
On 27 nov, 22:27, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
Brian Gideon <briangid...@yahoo.comwrote:
I love #2. I've seen your blog about beforefieldinit before. It
would be plain wrong to ask somebody that question in an interview :)

Indeed. Unless they were claiming to know absolutely everything about
C#, in which case anything is fair game.
By the way, you should keep adding to that page periodically or as you
run across a good one.

Absolutely - I've been meaning to do something like it for a while.
This thread was a catalyst :)

--
Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
World class .NET training in the UK:http://iterativetraining.co.uk
Here's another nice one:

Console.WriteLine(1 + 2 + "3");
Console.WriteLine("1" + 2 + 3);
Nov 28 '07 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Etienne Fortin | last post by:
I would like to share my disappointment of Microsoft with you readers. Be aware that I'm in no way a Microsoft "basher" and that, in fact, I use their programming technologies everyday. More...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.