views:

1597

answers:

9

You know how Steve Yegge recommends reading good code and bad code in order to learn from it? Well, I'm looking for good C# samples. Any suggestions?

A: 

Someone at work recommended Microsoft's "StockTrader Sample Application". So far it looks promising. You can download the applications here.

Esteban Araya
+4  A: 

Hanselman has a weekly source code section..

Gulzar
Looks good. Thanks!
Esteban Araya
A: 

Podder : http://joshsmithonwpf.wordpress.com/2008/03/05/podder-v2-has-been-released/ Family.Show : http://www.vertigo.com/familyshow.aspx

Both of these are very good C# WPF applications.

Max Schmeling
A: 

Star Trek Supremacy : http://www.codeplex.com/Supremacy

I've gone through the code base and learned a lot about the latest and greatest.

torial
+4  A: 

With the NetMassDownloader, you can download the .Net Framework source. I'd say that's probably among the best C# you can read because not only will you learn how MS does things, but you'll be increasing your knowledge of the internals of the Framework as well.

Wayne
Thanks. I didn't even know they had made the source code available.
Esteban Araya
If you have VS 2008, you can enable Framework debugging as well: http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx
Wayne
+1  A: 

I would personally recommend against looking on the internet. Maybe someone knows a really good site that I haven't seen, but most of the code I have seen online has been... troubling. On a place like CodePlex or CodeProject or those kinds of sites, you see a lot of people who haven't learned how to do it properly, trying to hack through until they get something working, and then having found that difficult and strange, posting their code with the best intentions for anyone else having trouble with it... There is some fantastic code on sites like that as well, but it's hard to separate the good from the bad, especially if you're trying to learn from it and might not be able to tell at first glance who does and doesn't know what they're talking about.
My suggestion for this would be to read a book, as at least in that case someone had to get it published and likely proofread by other developers (I've seen bad code in books too but it's not as prevalent) There are threads around here that talk about great books for developers, that might be a good place to start, since we're all developers here, so if we recommend a book it's probably not full of wtf code! And if it is, the suggestion would get quickly marked down through the power of peer review ;)
Look forward to seeing some of the responses in this thread, as I'd love some great code to learn from myself!

Grank
I completely agree. The other thing that's really annoying is that it is very difficult to evaluate code that is "Better" than you currently write. If you could tell a good new technique from a bad new technique, you wouldn't need to study, would you?
Bill K
+2  A: 

I would try the source code for Microsoft Enterprise Library for well written, well tested (includes unit tests code) and highly focused components.

Sergio Acosta
+13  A: 

If you are looking for decent source code for well written projects I asked a similar question:

Open source C# projects that have extremely high code quality to learn from.

People gave some pretty good suggestions there:

Simucal
Thanks for the summary Simucal. I see you've mastered Joel's advice ;)
Esteban Araya
+1 for Sharp Develop, I don't use it anymore, but the codebase was a pleasure to see
johnc
+1  A: 

Jon Skeet's site has a bunch of well thought-out Java and C# articles, with extensive code samples. He's also got an extremely well-commented .NET utilities library (there's a Java one too) that illustrates a number of best practices.

Michael Petrotta