C# in Depth

Jon Skeet

Mentioned 33

A guide to the key topics of C# covers such topics as lambda expressions, LINQ, generics, nullable types, iterators, and extension methods.

More on Amazon.com

Mentioned in questions and answers.

I've jumped into the C# bandwagon and was wondering if there's an equivalent of Joshua Bloch's Effective Java for the C# world.

I've already being able to apply some Java knowledge to C# given their similarity but I'm interested in knowledge to make the most effective use of C# specific features. For example, Generics are not implemented equally in Java and C#, so it's not clear to me if the Java Generic "techniques" will work in C# as well.

I'm mostly interested in C# 3.0. That is (of course) unless you guys think I would benefit for looking into versions 1 and 2 features.

I think Framework Design Guidelines is the closest. While I don't think it's comparable to Effective Java in terms of depth, I haven't read found any better book in the same category.

C# in Depth is great, but it focuses more on the language than design issues in .NET. Therefore, I wouldn't put it in the same category with Effective Java.

alt text

Effective C# and More Effective C# by Bill Wagner. The second book deals with C# 2 and 3.

Either here and here on Amazon.com

or here and here on Amazon.co.uk

There's a new version of Effective C# (Amazon UK) that covers C# 4.0.

Beaten to it by Andy, but I was looking up the links.

Jon Skeet's C# In Depth is a favorite among StackOverflow users.

C# In Depth

Since you want something in the same line of Effective Java the following two books are very similar:

Effective C#

More Effective C#

Jon Skeet's C# In Depth is also worth mentioning.

How about Effective C#?

There are two books Effective C# and More Effective C# by Bill Wagner that are similar to Effective Java.

I found CLR Via C#, by Jeffery Richter, to be very good. It discusses the CLR and framework in some depth and gives you a greater understanding of how to use various feature along with potential pitfalls.

I have read on Stack Overflow some people that have converting to C#2.0 to C#3, but is it really worth it?

I have a project that is done at 75% before going in maintenance phase. I am asking to myself if it is worth it to switch to C#3.0?


The project will have a web interface now so before entering the maintenance phase we have to develop the web part (all was done for internal purposes with Windows Forms). Most parts will be resused (back-end). Most people have said that it wasn't worth it in the past because it was already at 75%... but now do you still think it's not worth it?

What have been done finally

Finally since we are continuing the project with the web interface we will update to 3.5 for the new year. Thank you everybody for all your input.

It really depends on what you need to do. If your project requires Lambda Expressions where you're query objects with a clear syntax, you should look at 3.0.

I am currently reading C# In Depth by Jon Skeet, and he takes the approach of laying out a solution in C# 1.15, then evolves the solution to depict the new and useful functionality that you get in 2.0 and 3.0. This type of progression would be a perfect means to answer your questions. The book reads well too so I am finding I am getting through it quickly.

It seems that C# 3 hit me without me even noticing, could you guys tell me about good in depth guides to C# 3? from lambda to linq to everything else that was introduced with the third version of the language.

Printed books would be nice, but online guides would be even better!

I've found C# 3.0 in a Nutshell to be very useful.

I found Pro LINQ: Language Integrated Query in C# 2008 to be very helpful for this. It has a chapter which covers all the new language features in 3, and of course the rest of the book goes into a deep dive on LINQ. I would highly recommend it.

Picking up C#, can't seem to find any useful reference to this, other than examples.

So, what is Dim in C#?

I can suggest Learning C# 3.0 (and later, maybe C# 3.0 in a Nutshell and C# in Depth) to learn C#. It's probably a good idea to learn the language fundamentals and start "thinking in C#", instead of trying to "translate" or "convert" your thoughts from VB to C# (or any other language, for that matter).

Edit: That said; you do want to compare the new language you're learning to the one(s) you already know whilst you go along, to learn the differences between the languages. In my opinion, when learning a new language, it's more about grasping the principles and fundamental differences :)


I'm a long time Unix and Linux person with about 30 years and 14 years experience in those technologies, respectively. But wanting to expand my toolbox, I was trawling SO for hints on learning Sharepoint and I was wondering about Jon Skeet's answer to the question "How to begin as a .net and SharePoint developer" where he suggests learning .NET and C# before learning ASP.NET and Sharepoint.

Should I learn .NET and C# before getting involved with ASP.NET and Sharepoint? And can anyone recommend good books for the four technologies?

On SO so far, we've had questions for book recommendations for learning Sharepoint and ASP.NET but I haven't found anything about a "*nix head" dipping his toes into the MS waters for the first time.

At the moment I have Jon's recommendations from his answer above but I've been also been looking at the Head First C# book and a couple of O'Reilly Nutshell books.

The list of possible books I have so far is:



N.B. The Sharepoint list was obtained from the accepted answer to the question "WSS/MOSS". Thanks Pascal Paradis.

Any one help with the suggestions for learning .NET and ASP.NET?

Any thoughts on these books?


I suggest you start learning from a book that will introduce you both to .NET and C#. When you will understand .NET world, you can go further to ASP.NET. Since you come from *nix world, you should learn how different .NET world is from your previous experiences, and even from Windows itself. I spent some time reading Andrew Troelsen’s book, and I think they are quite ok to start, and then move to ASP.NET. From the list above I have heard, that Liberty’s book is quite ok.

Troelsen: http://www.amazon.com/2008-NET-Platform-Fourth-Windows-Net/dp/1590598849/ref=sr_1_1?ie=UTF8&s=books&qid=1247572543&sr=1-1

Absolutely you need o learn C# (or VB.NET or any .NET language) and ASP.NET before Sharepoint. Actually Sharepoint is built upon ASP.NET. Though you can use sharepoint by itself (create document libraries and stuff) from the browser, without having to deal with asp.net, but a lot of sharepoint things require .NET and ASP.NET. For example, SmartWebParts in sharepoint depend on creating asp.net user controls, also features in Sharepoint depends on .NET. So yeah! You have to learn C# and ASP.NET for doing real sharepoint stuff.
For the books thing, for me I think that
Inside Windows Sharepoint Services is an awesome book, it's the best one for programmer (IMHO of course).
Pro C# and the .NET 3.5 is very highly recommended for C#
ASP.NET 2.0 Web Site programming Problem, Design, Solution would be my recommendation for ASP.NET

You need knowledge about C# and .NET to developing ASP.NET apps or for SharePoint. Because both technology have same base and it's .NET

Head First C# for absolute beginner in programming (OOP) and C#. And it's good for you if you haven't knowledge about object programming, but if you familiar with OOP, this book wasting your time.

Best way how to get in .NET and C# is C# in Depth: What you need to master C# 2 and 3

This really deserves something more than "Should you walk before you can run?", which was my first thought :)

With 30 odd years of experience (I assume programming experience), you should not really learn the basics, you need to get in depth understanding of the C# developement environment, IIS, SQL Server and SharePoint (in roughly that order). To be efficient, you need to compare these technologies and see how they are different from what you are used to rather than reading yet another book that starts with variable declaration syntax.

I personally would get more from time spent with an expert, but that is not usually an option. Fortunately many of these people blog and those can be really illuminating. (see Eric Lippert)

When reading the detail, you will most likely be able to understand how the details operate without needing a full chapter.

Small snippets of information are going to be more useful to you than large amounts of basic knowledge. E.g. I assume that a snippet of information such as "SharePoint stores all the documents for a Site Collection as a binary field in a single table." will provide you with more information than a several thousand word overview of SharePoint site collections.

I am new to LINQ and discovered yesterday that you can have multiple where clauses such as:

var items = from object in objectList
where object.value1 < 100  
where object.value2 > 10  
select object;

Or you can write:

var items = from object in objectList
where object.value1 < 100  
   && object.value2 > 10  
select object;

What is the difference between the two?

At the most basic level, you get two Where operations instead of one. Using Reflector is the best way to examine what comes out the other end of a query expression.

Whether they get optimised down to the same thing depends on the actual LINQ provider - it needs to take the entire tree and convert it to another syntax. For LINQ To Objects, it doesn't.

C# in Depth is good to give you an understanding of this topic.

I used to be a Java nerd back in college, but ever since then I haven't touched it. My work for the last 3-4 years has mostly been in Python and C++, and I have forgotten a lot of in's and out's of Java.

So, what is the best (and fastest) way to get back in the groove with a language? Any suggestions on small projects that make you use (and hence relearn) old languages that you know already?

A related question is, how do you guys stay in touch with technologies that you have learned but haven't had a chance to use in a long time?

Read advanced books on the topic. Some examples:

Effective Java (2nd Edition) - Joshua Bloch

C# in Depth: What you need to master C# 2 and 3 - Jon Skeet

These two as examples provide you with the changes introduced in the last versions of the languages which should be enough to get you back on track combined with some sort of a pet project as mentioned by Pax.

I try to read some advanced books on languages which I don't use activly at the moment too, but this depends on my motivation..

With best regards

I want to learn C# (on Linux, so using Mono), and I'm looking for some guide that taps into the knowledge I already have of other languages; most notably C, C++ and java (but also python, Haskell, lisp, and perhaps a few others).

So far all I've found on the web are combined introduction-to-programming and introduction-to-C# texts, but they all fail because I get bored and can't stick to my learning plan.

Does anyone have a suggestion for something good to read?

Broadening this question up, how do you learn a new language that's similar to languages you already know in a way that taps into the knowledge you already have? Do people write these kind of tutorials? Do you just grab a cheat sheet? Do you have an array of exercises you force yourself through?

Edit: I don't know any other Microsoft development... thingies. I wrote a little bit VB around eight years ago, but I don't remember any of that. I have no ASP experience, no experience with anything else .NET, no MS languages or libraries. Even though I have developed on Windows, I haven't done capital-D Windows Development. Please consider this when making a suggestion.

  1. Pick up a real project. Then you will face real problems.
  2. Find person who already knows C# well. He may give you valuable advices.
  3. Get a good book such as C# 3.0 Complete reference by Herbert Shildt. MSDN is good, but sometimes it is easier to read a good book than documentation.

C# is something of a "next-generation" Java, and Microsoft's old Java team did a lot of the development work on the language (plus Anders Heilberg, of Borland Pascal and Delphi fame).

There are two essential improvements in C# over Java.

  • C# generics have a better implementation, with the huge improvement being that in C#, generics retain full type information at run-time. This will improve even more in C# 4.0, with covariance and contravariance.
  • LINQ (Language INtegrated Query) gives you a SQL-like query language that is fully integrated into C#. You can query object collections, XML, databases, web services, or anything else. The .NET framework includes interfaces for developing your own LINQ data providers, so there are essentially no limits on what LINQ can query.

So probably the best way to approach C# is to think first in terms of Java, and look at the enhancements. Jon Skeet's C# in Depth might be the best starting point; it will cover all the real meat of C# that differs from other languages.

Where do you get the best in-depth information for C# programming? I'm looking for tutorials, examples, blogs, specialized forums etc. dedicated to c#.

I recommend you Jeffrey Richter's "CLR via C#" book. You can learn CLR features and how does c# implement them. Also you can learn a lot about multithreading in c#, localization, appdomains etc. .net topics.

You can't go wrong with these:

Hai guys,

My fellow developers were talking about lambda expressions this morning. So i decided to ask it here in SO

  • when should i use lambda expression which comes with C# 3.0?

Short answer: read "C# in depth" from SO's top-most voted fellow Jon Skeet. Its an excellent book and you will learn all about the new C# 3 features, especially when to use them, including Lambda expressions.

I have heard people state that Code Generators and T4 templates should not be used. The logic behind that is that if you are generating code with a generator then there is a better more efficient way to build the code through generics and templating.

While I slightly agree with this statement above, I have not really found effective ways to build templates that can say for instance instantiate themselves. In otherwords I can never do :

return new T();

Additionally, if I want to generate code based on database values I have found that using Microsoft.SqlServer.Management.SMO in conjunction with T4 templates have been wonderful at generating mass amounts of code without having to copy / paste or use resharper.

Many of the problems I have found with Generics too is that to my shock there are a lot of developers who do not understand them. When I do examine generics for a solution, there are times where it gets complicated because C# states that you cannot do something that may seem logical in my mind.

What are your thoughts? Do you prefer to build a generator, or do you prefer to use generics? Also, how far can generics go? I know a decent amount about generics, but there are traps and pitfalls that I always run into that cause me to resort to a T4 template.

What is the more proper way to handle scenarios where you need a large amount of flexibility? Oh and as a bonus to this question, what are good resources on C# and Generics?

You can do new T(); if you do this

public class Meh<T>
  where T : new()
  public static T CreateOne()
    return new T();

As for code-generators. I use one every day without any problems. I'm using one right now in fact :-)

Generics solve one problem, code-generators solve another. For example, creating a business model using a UML editor and then generating your classes with persistence code as I do all of the time using this tool couldn't be achieved with generics, because each persistent class is completely different.

As for a good source on generics. The best has got to be Jon Skeet's book of course! :-)

I've been programming since I was about 17, admittedly I wasn't the strongest programmer at the time but I've buckled down and now I'm comfortably completing assignments in my 3rd year of University. I was in a Computer Games Programming course but promptly switched to the generic Information Technology course with a heavy emphasis on programming once I realised the course I was on is one of the lowest rated in the country. I wanted to keep my options open and not down the games programming route (Besides I have XNA to do that in my free time).

I was thinking to myself what I would actually do once I complete my degree, I'm heavily based towards the C# programming language and have spent a great deal of time using Windows Forms and Console Applications however I do have some experience with C and C++.

I am just curious to hear other peoples opinions on the best way to get a graduate job for someone who isn't exactly "overly confident" with his own skills. I have been looking into a few start up companies and also a few graduate jobs at Microsoft etc.. but i don't want to get in too over my head.

Also at a time of global recession I assumed companies would rather invest in somebody who has strong confidence and can get the job done with some background experience as opposed to a graduate fresh out of University. I'm in Derby at the moment and I have been for 21 years (Since I was born), i'll be moving to Manchester when I graduate so hopefully there will be many more opportunities for me there as it is a much bigger city as opposed to Derby.

Sorry if this is repeated somewhere else, I did search but didn't seem to find anything matching my question.

Can anybody recommend some respected C# text books, I have several already (Such as C# 3.0 Unleashed!) but I always find one book has something another doesn't.

Note: Thankyou for re-opening, i'd like to get as much input as possible. This questions is programming related and not an exact duplicate.

Make sure you do at least one internship while still in college. Most CS graduates have at least one internship so if you don't have one it will definitely put you at a disadvantage.

Another great thing to do is get involved with an open source project. This looks good on a resume and is a public demonstration of your coding skills. Also it'll give you great experience.

Best C# book available is from Jon Skeet.

C# in Depth: What you need to master C# 2 and 3 http://www.amazon.com/Depth-What-you-need-master/dp/1933988363/ref=sr_1_1?ie=UTF8&s=books&qid=1265137384&sr=8-1

I'm reading about C# and closure, various articles, Jon Skeet's awesome "C# in Depth" and I see statements like "C# and ruby implement lexical closure".

Why do the authors include the word "lexical"? Why not just say they "implement closure"?

What would it mean if it just implemented "closure", and not "lexical closure (if that's even possible)?

Lexical closure is just a more specific name for closure.

As you know, a closure allows a function to use variables from the scope where it was created, even if is executed from a different scope. Such a scope is also called a lexical environment, and that's where the term lexical comes from here.

I'm reading Jon Skeet's C# in Depth.

On page 156 he has an example, Listing 5.13 "Capturing multiple variable instantiations with multiple delegates".

List<ThreadStart> list = new List<ThreadStart>();

for(int index=0; index < 5; index++;)
    int counter = index*10;

foreach(ThreadStart t in list)



In the explanation after this listing, he says "each of the delegate instances has captured a different variable in this case."

I understand this well enough because I understand that each time you close over a variable the compiler generates IL that encapsulates it in a new class made specifically to allow that variable to be captured (essentially making it a reference type so that the value it is referring to doesn't get destroyed with the stack frame of the currently executing scope).

But then he talks about what would have happened had we captured index directly instead of creating the counter variable - "all the delegates would have shared the same variable".

This I don't understand. Isn't index in the same scope as counter? Why would the compiler not also create a new instance of index for each delegate?

Note: I think I figured it out as I typed this question, but I will leave the question up here for posterity. I think the answer is that index is actually in a different scope as counter. Index is essentially declared "outside" the for loop...it is the same variable every time.

Taking a look at the IL generated for a for loop, it proves the variables are declared outside the loop (length and i were variables declared in the for loop declaration).

.locals init (
    [0] int32 length,
    [1] int32 i,
    [2] bool CS$4$0000

IL_0000: nop
IL_0001: ldc.i4.s 10
IL_0003: stloc.0
IL_0004: ldc.i4.0
IL_0005: stloc.1
IL_0006: br.s IL_001b
// loop start (head: IL_001b)
    IL_0008: nop
    IL_0009: ldloca.s i
    IL_000b: call instance string [mscorlib]System.Int32::ToString()
    IL_0010: call void [mscorlib]System.Console::WriteLine(string)
    IL_0015: nop
    IL_0016: nop
    IL_0017: ldloc.1
    IL_0018: ldc.i4.1
    IL_0019: add
    IL_001a: stloc.1

    IL_001b: ldloc.1
    IL_001c: ldloc.0
    IL_001d: clt
    IL_001f: stloc.2
    IL_0020: ldloc.2
    IL_0021: brtrue.s IL_0008
// end loop

One thing I think the book might have done better regarding this subject is really explain what the compiler is doing, because all this "magic" makes sense if you understand that the compiler is wrapping the closed over variable in a new class.

Please correct any misconceptions or misunderstandings I might have. Also, feel free to elaborate on and/or add to my explanation.

It sounds like you've worked out the answer - you don't get a new index instance each time round the loop. If you consider the ways you're allowed to modify the index value inside the loop - eg. you can increment it if you want to skip items, set it back to zero in some cases, or anything else you like - it should be clear that you've only got one instance of index, not a new one for every iteration.

On the other hand, a new counter is created on every iteration - if you made a change to it at the bottom of that loop, it would have no effect on the counter variable that the next iteration uses.

foreach loops used to reuse their loop variable, in the same way as for loops, and this was a common gotcha for people - see Is there a reason for C#'s reuse of the variable in a foreach?

Eric Lippert explains that they've changed foreach in C# 5 to get a new variable every time, and also that they're leaving for as-is.

I've always worked with the standard Linux web stack (linux, apache, php, python, mysql) but have been given a great job opportunity working with a group that works with the Microsoft Web Stack (IIS, ASP.NET, MSSQL, C#).

There seems to be a pretty good Microsoft following here on SO. Where should I begin? Specific books, tutorials, online resources are appreciated.

If books are your best learning source then some I found helpful:

The third book is about the common language runtime (what executes compiled C# code).

I would suggest you read C# in Depth by Jon Skeet, who is a user here at SO. It will definitely help you master C#. The rest is gravy.

I have a team of junior developers and they want to have better understanding and usages of generics. Anyone recommend good tutorial or articles samples that are good places to start.

Bill Wagner's More Effective C# has some really good content on Generics.

I have recently been working with Python using Komodo Edit and other simpler editors but now I am doing a project which is to be done in C# using VS 08. I would appreciate any hints on how to get productive on that platform as quickly as possible.

Get an excellent book and start reading. I have Pro C# 2008 and the .NET 3.5 Platform.

Since you have a project to work on that should help greatly as well.

As far as becoming proficient with C# I would highly recommend Programming C# and C# in Depth.

For Visual Studio, start poking around in the IDE a lot, play around, get familiar with it. Start with simple projects and explore all the different aspects. Learn how to optimize Visual Studio and get familiar with some of the great keyboard shortcuts / hidden features of the IDE.

Definitely do each of the following at least once:


  • Create a simple console application (e.g. hello world)
  • Create a class library (managed .dll) and use it from another application you create
  • Create a simple windows application
  • Create a simple asp.net web app


  • Debug a command line app
  • Get familiar with: breakpoints, the locals and watch windows, step over, step into, step out of, continue, stop debugging
  • Create a command line app which uses a function in a class library. Store the dll and symbol file (.pdb) for the library but delete the source code, debug through app as it goes into the library
  • Debug into a webservice
  • Learn how to use ILDasm and ILAsm

Command Line:

  • Get familiar with the Visual Studio command line environment
  • Build using only the command line
  • Debug from the command line using devenv.exe /debugexe
  • Use ILDasm / ILAsm from the command line to disassemble a simple app into .IL, reassemble it into a differently named file, test to see that it still works


  • Create unit tests (right click in a method, select the option to create a test)
  • Learn how to: run all unit tests, run all unit tests under the debugger, rerun failed unit tests, see details on test failures, run a subset of unit tests
  • Learn how to collect code coverage statistics for your tests

Source Control:

  • Learn how to interact with your source control system of choice while developing using VS

Refactoring et al:

  • Become familiar with all of the built-in refactorings (especially rename and extract method)
  • Use "Go To Definition"
  • Use "Find All References"
  • Use "Find In Files" (ctrl-shift-F)

IDE & Keyboard Shortcuts:

  • Learn how to use the designer well for web and winforms
  • Get very familiar with the Solution Explorer window
  • Experiment with different window layouts until you find one your comfortable with, keep experimenting later to see if that's still the best choice
  • Learn the ins and outs of intellisense, use it to your advantage as much as possible
  • Learn the keyboard shortcut for everything you do

I left the .net about 3 years back when I was working on .net 2.0. And in these three years I wasn't working on .net at all. Now, I have got a project which is in .net 3.5. But I have noticed there are a lot of technologies introduced between these two versions.

Is there any resource which can help me to quickly grasp the things which are introduced after .net 2.0

It may help that my major work is in asp.net with C#

I've just bought this book for the same purpose myself: C# in Depth: What you need to master C# 2 and 3 by Jon Skeet. I consider it a good start.

What are good c++ to C# articles/tutorial or books? I am reading http://msdn.microsoft.com/en-us/magazine/cc301520.aspx and will read http://andymcm.com/csharpfaq.htm and http://www.ondotnet.com/pub/a/dotnet/2002/02/11/csharp_traps.html afterwards. Have any of you read any good books for ppl who have a strong understanding of programming && || C++ on the C# language (and libraries)?

If you're coming from C++, I think the best book to start with is CLR via C#. It will give you both a solid introduction to C# while also acclimating you to life in the CLR. The latter may be more of a stumbling block for someone with a solid C++ background.

I am currently reading Jon Skeet's C# in Depth. It is the best treatment I have seen for C# 2 and 3. If you are an advanced C++ programmer and you have some familiarity with C#, this is the book to take your C# competence to mastery.

Jon provides insights into the evolution of C# and insights into the various new language features. Not just the "hows" but also the "whys". Again, approach it after reading a beginning C# book. It doesn't cover the basic stuff which is covered many times by numerous other C# books.

I recommend Accelerated C# book for programmers who's came from C++ and Java Languages.

I am novice to .NET framework and started working on developing a web application, it would be great if I can find answers to couple of my novice queries listed below (I really appreciate your response).

  1. Where we can find best practices related to design, coding, testing and deployment of .NET (ASP.NET/C#)? - I have googled and found many resources not sure which is the best?.

  2. Which is the best logging framework for .NET? - log4net or something else? - any suggestions on using ASPECT.NET?.

  3. Which is the best database connection pooling framework? (is there any) - any references to resources would be of great help.

  4. We are developing a component that does network updates (altering users with emails) - any good messaging platforms? and what are the best practices to be followed when developing resource intensive services as a part of main web application.

Thanks a lot for your time and looking forward to interact with you all in near future.

Regards Vijay R

Database Connection Pooling

If you are using SQL Server then database connection pooling will be done for you automatically. Unless you have an extremely high transaction rate, this shouldn't be a concern.

Design, Coding, Testing, etc. can really be answered on two levels.

If you are looking for resources for Agile, for example, (the "meta" level) then Robert Martin's works are generally considered the reference. He has one called "Agile Principles, Patterns and Practices in C#" that is good if you are a C# developer. I can recommend it although I will tell you that it is pretty derivative of earlier works and his C# isn't really world class (see Jon Skeet's book, mentioned below, for that). Martin's book is very useful for learning Agile methods and design patterns but not so much for learning coding techniques.

For more of an algorithm-at-a-time perspective on Design Patterns, I can recommend "C# Design Patterns" by James Cooper.

For a deeper perspective on the language itself, see Jon Skeet's C# in Depth. It is far and away the best advanced C# book I own.

Finally, there are many questions related to Test-Driven Development here on SO so make sure you browse around!

If you like what you see and decide to use Test Driven development techniques, then you'll either adopt Microsoft's testing library (built into Visual Studio) or you can go for the open source standard NUnit. I use and strongly recommend NUnit. The people at Testdriven.net have built a nice tool that lets you not only run your NUnit tests from within Visual Studio but also provide a great test-coverage analysis tool! I like their tools a lot and use them constantly.

EMail and SMTP-based Messaging

Finally, if you are doing a lot of work using email as a messaging platform, then you'll want to check out the AspNetEmail library. It is far and away the best email platform available. It not only provides things like the automatic processing of ASP.NET web forms, mail merges, etc. etc. it also features technical support with guys who know more about SMTP than anyone else I've ever met. Highly recommended!

I know very little about C# or .net but I am interested in learning about them.

One thing that intrigues me is that I keep hearing that "C# 3 is really great".
Why is that? What is the difference from C# 2. Are the differences just in C# or in .net also?

Thanks in advance.

I have a little article about this: the Bluffer's Guide to C# 3. Obviously there are more details in my book but it should be enough to get you going. In short:

  • Automatically implemented properties:

    public int Value { get; set; }
  • Object and collection initializers:

    Form form = new Form { Size = new Size(100, 100),
                           Controls = { new Label { Text = "Hi" } }
    List<string> strings = new List<string> { "Hi", "There" };
  • Implicitly typed local variables:

    var x = new Dictionary<string, int>(); // x is still statically typed
  • Implicitly typed arrays:

    DoSomething(new[] { "hi", "there"}); // Creates a string array
  • Anonymous types:

    var jon = new { Name = "Jon", Age = 33 };
  • Lambda expressions (like anonymous methods but shorter):

    Func<string, int> lengthFunc = x => x.Length;
  • Expression trees:

    // Representation of logic as data
    Expression<Func<string, int>> lengthExpression = x => x.Length;
  • Extension methods: (static methods which act like instance methods on the type of their first parameter)

    public static string Reverse(this string text)
        char[] chars = text.ToCharArray();
        return new string(chars);
    string hello = "olleh".Reverse();
  • Query expressions:

    var query = from person in people
                where person.Age > 18
                select person.Name;

I want to learn C# and the .Net Framework as well.

I have no idea on the Microsoft .Net and C# framework but I once programmed on their Microsoft Visual Basic 6 with experience on making COM Components (OCX and DLL).

I have an experience programming on java and have fair knowledge of Object Oriented Technology. But I am currently confused on the number of books currently written for C#.

I want a book that will not explain me the for loop or iterative looping on one chapter but more on the language itself. I've heard that C# is a close cousin of Java so I think I just want to know the syntax.

Since I dont know C# and .Net framework< i would like a book that could focus on them.

Currently, as I have viewed from the net. I have this list of books:

  • Head First C#
  • Illustrated C#
  • MS C# 2008 Step By STep
  • Illustrated C#
  • C# 3.0 in a Nutshell
  • Wrox Beginning C# 2008
  • C# in Depth

From the review in amazon, they all look good but I dont know which one of them or that is not in the list that I have would suit me.

I definitely want to learn C# so hopefully someone can help me

Effective C# and More Effective C# by Bill Wagner are worth a read.

Or Effective C# and More Effective C# if you're in the States.

C# 3.0 in a Nutshell has really helped me understand C# in depth; I recommend it for anyone.

Although I wouldn't say it's really a beginner's book per ce.

alt text

I'm a fan of the CLR via C#, by Jeffrey Richter, a man very, very wise in C#-fu.

Also, check out our very own Jon Skeet's C# in Depth.

Both are great reads.

Most C# developers developers, like me have a good solid grasp on the .net framework and the C# language. But I've yet to come across a book that can take a very good c# developer to the next level of C# mastery.

I am looking for a book that can help me make that transition. Dealing with issues like theory on having more robust C# code when connecting to external systems etc. Error logging techniques, and generally better memory usage, and re factoring.

Anyone know of a good book, that's worth the read?

The best book I have found for C# internals is CLR via C# by Jeffrey Richter.

Effective C# and More Effective C# by Bill Wagner come highly recommended

Not a C# book per se, but Design Patterns (Gamma et al) might be a good introduction to more abstract, architectural concepts.

If you want to read the "source" of a language in C you go to C Programming Language by Kernighan; Ritchie; 0131103628

And in Java you read Goslings The Java(tm) Language Specification; 0321246780

But what do you read if you want to read a good book about the "specs" on C++ and C#?

C++: Stroustrup's book and/or Stroustrup's D&E or Stroustrups ARM though the latter two are not in date. The ISO spec is available (see Charles bailey's answer) and is the final word if that's the type of doc you want. The most thorough answer is in the comments by aJ :- The Definitive C++ Book Guide and List. The equivalent of K&R for C++ is the first one.

C#: The C# Programming Language (3rd Edition) by Anders Hejlsberg, Mads Torgersen, Scott Wiltamuth, and Peter Golde). If you're looking for the generally accepted definitive book on C#, that's C# in depth.

I'm moving from .NET Framework 2.0 to 3.5.

I'm not a big fan of LINQ. So beside of that and "extensions" what should I do know and take advantage of in .NET Framework 3.5?

If you are interested in this topic and want to explore in some depth I very strongly recommend that you get a copy of Jon Skeet's C# In Depth. Every answer that you'll get here will be only part of the story whereas Jon's book walks you through C# 1 to 2 to 3 and shows you the application of new features in each release.

Update: The book is also available in O'Reilly's Safari. It is really a read and ponder kind of book, though, so I think that you'll prefer the deadwood version.

The following example is taken from C# in Depth: What you need to master C# 2 and 3, and seems to only only cause a breaking change as jskeet has identified, but be wrong. Please explain:

delegate void SampleDelegate(string x);

 public void CandidateAction (string x)

public class Derived: Snippet
   public void CandidateAction (object x)

Derived x = new Derived();
SampleDelegate factory = new SampleDelegate (x.CandidateAction);
factory ("test");

Now, why should it work altogether as SampleDelegate accept string not the object. And to my knowledge, object doesn't derive from the string. It is the other way around. That's what contravariance permits under c# 2.0. The seems to demonstrate the opposite effect.


Conceptually, Derived.CandidateAction's signature is saying, "I can handle any object you want to throw at me." SampleDelegate's contract is "You have to be able to handle a string." Now if a method can handle any object, it can certainly handle a string. So Derived.CandidateAction is capable of fulfilling what SampleDelegate needs, and can therefore be assigned to a SampleDelegate variable.

I wrote a more detailed discussion of this (admittedly from a C# 4 point of view) at http://hestia.typepad.com/flatlander/2008/12/c-covariance-and-contravariance-by-example.html.

using c#, vs2008, winforms

If i am passing a parameter via a property to a child form from a parent form, or infact via a property to any class, and the the paramater im passing in C# is a reference type created in the parent form, does it get passed as a ref or value by default ?

Eg if i pass a dataset via a property. And if it does get passed by value, can you make it passed by ref via a property ? Or should i just pass it via a method paramater, is that better practice ?

Basicaly i want to retrieve a populated object back to the parent form, and feel passing by ref an object that is created in the parent form is better.

For reference types, a reference to the variable is passed by value. Unless, of course, you use the ref or out keywords in C# to alter that behaviour.

That means that a DataSet-valued property passes, in actual fact, a reference to a DataSet instance, and passes it by value.

Jon Skeet's "C# in Depth" is a great reference (no pun intended) on these matters.

Why I can use Object Initializers in Visual Studio 2008 Windows projects, etc targeted to .NET 2.0 but cannot - in ASP.NET projects targeted to .NET 2.0 ?

I understand that this is C# 3.0 features, but don't - why this possible to use in .NET 2.0 projects.

The best source of information on advanced featured in C# and how they have evolved from C# 1.0 through 3.0 is Jon Skeet's book. He is here on SO quite often and may even offer some additional insight. However, you really should have the book.

I have been programming with .NET 2.0 version for quite sometime and would like to move onto the latest version to keep up-to-date with latest technology. the latest version seems to have many new concepts like WPF, WCF, LINQ etc. what is the best way to quickly learn the basics of these new technologies without spending months reading big 500/1000 page books? when I was learning ASP.NET 2.0 first time, I found the quickstart tutorial on Microsoft ASP.NET site very useful. it helped me to learn the concepts very quickly without having to spend lot of time reading big books. Are there any similar tutorials or something of that kind for .NET 3.5, with some practical examples (not just theory) to get hands-on experience? Thanks for your help.

I found our own Jon Skeet's C# in Depth to be a very clear guide to move from .NET 2.0 to .NET 3.5. So when C# is your language of choice, check it out (or wait a little for the second edition which will also include C# 4)

I have some experience with C#, and would like to improve my knowledge of its latest improvements. I am in the middle of reading and enjoying "Effective C#" by Bill Wagner right now. However, I would appreciate more examples, especially with lambda expressions and such.

Any suggestions are greatly appreciated. High quality resources are preferable, and it does not matter much if they are free or not.

C# in Depth - Jon Skeet

The Second Edition is in the process of being written. It definitely has some pretty good stuff including Lamda's and dynamic stuff.

P.S. - No pressure Jon...

My personal recommendation would be CLR via C# - an excellent book. I have not read C# in depth , but have heard its a very good book too.

I wish to become a good developer in C# (especially .NET environment (i.e both windows app & web app)).

Suggest me the way to achieve the same..... It may be books, magazines, journals, code samples, etc.

Two books I found to be very helpful have been Programming C# and C# in Depth. These books are aimed at developers with existing experience in other languages, they may not be helpful if you are less experienced. Some of the other answers may have better suggestions for folks just beginning to learn programming.

You'll probably want to get Visual C# 2008 Express. It's free and very full-featured, you can get started experimenting with code very quickly and easily.

I would recommend starting with the absolute core parts of C# - learn about the type system, strings, numbers, IO, collections etc. I'd personally do this with console applications, where you don't need nearly as much code to get a result as with a GUI, and you can concentrate on the topic you're trying to learn about.

In terms of books, C# 3.0 in a Nutshell is very good. If you're really not a console kind of person, Head First C# may be up your street - it's not my preferred style, but many other people like it. However, make sure you get the latest printing, as lots of errors have been corrected.