CLR via C#, Second Edition (Developer Reference)

Category: Programming
Author: Jeffrey Richter
All Stack Overflow 53
This Year Stack Overflow 1
This Month Stack Overflow 1


by serg10   2019-07-21

I have recently done exactly this and found the two most valuable books to be:

CLR via C# by Jeffrey Richter. Very well written and gives a great insight into the .net runtime - lots on the concepts you will already know from java such as garbage collection, threading, generics, etc. Plus really good in depth coverage of c# constructs like delegates and events that don't come with java (yet).


Pro C# and the .net 3.5 Platform by Andrew Troelsen. This is much more of a general text on the .net ecosystem. It has an excellent core language section, but then also gives a really good overview of the major libraries and apis - WPF, WCF,, etc.

Those should provide you a solid foundation and are both pitched perfectly for the experienced programmer. After that, you'll probably end up looking for something more specific to the technology you are working in - a detailed book in your case - but I constantly refer to both of these, so it is money well spent imho.

by anonymous   2019-07-21

The best book to get on the subject that I've read is Jeff Richter's book, CLR via C#:

If you want a VB.NET version, they have that for the first edition of the book, but I don't think there was enough interest to translate the book into VB.NET for the second version. If you want to really learn .NET, you should get comfortable with C#. In both languages, memory is managed by the CLR.

by ng5000   2019-07-21

If you've got a C++ background and aren't afraid of pointers/stack/heap etc, then this book (CLR vi C#) will give you a superb understanding of .Net. It is very readable and will provide the foundations you need to be able to understand just about any new/up and coming .Net technology (e.g. Linq, extension methods, etc).

VS2008 express editions are available free here and are good enough for writing small apps.

by lfoust   2019-01-13

The best answer I have ever heard about using the provided type aliases in C# comes from Jeffrey Richter in his book CLR Via C#. Here are his 3 reasons:

  • I've seen a number of developers confused, not knowing whether to use string or String in their code. Because in C# the string (a keyword) maps exactly to System.String (an FCL type), there is no difference and either can be used.
  • In C#, long maps to System.Int64, but in a different programming language, long could map to an Int16 or Int32. In fact, C++/CLI does in fact treat long as an Int32. Someone reading source code in one language could easily misinterpret the code's intention if he or she were used to programming in a different programming language. In fact, most languages won't even treat long as a keyword and won't compile code that uses it.
  • The FCL has many methods that have type names as part of their method names. For example, the BinaryReader type offers methods such as ReadBoolean, ReadInt32, ReadSingle, and so on, and the System.Convert type offers methods such as ToBoolean, ToInt32, ToSingle, and so on. Although it's legal to write the following code, the line with float feels very unnatural to me, and it's not obvious that the line is correct:
BinaryReader br = new BinaryReader(...);
float val  = br.ReadSingle(); // OK, but feels unnatural
Single val = br.ReadSingle(); // OK and feels good

So there you have it. I think these are all really good points. I however, don't find myself using Jeffrey's advice in my own code. Maybe I am too stuck in my C# world but I end up trying to make my code look like the framework code.

by anonymous   2018-03-19

Jeff Richter (author of CLR Via C#) explains why in this article on Safe Thread Synchronization.

Specifically, in that article the section "Why the Great Idea isn't So Great" answers your question.

It's actually a chapter from the book CLR Via C#.

In summary, having a private object as the "synclock" object allows your class to encapsulate and control any locking your class needs. Therefore regardless of how many clients use your class, locking is performed consistently and correctly.

by anonymous   2017-08-20

I'm not going to be able to help out with your MonoDevelop question and XSP2 since I haven't used Mono, but I can help with some of your other questions.

When you have an app, what are the executable scripts (ie. .php for PHP)?

ASP.NET pages have a .aspx extension (although this is configurable). When a page is first requested the ASP.NET run-time parses an ASPX file and compiles a class from it. This compiled class is executed within the ASP.NET application run-time.

.cs files are often associated with a .aspx file by development environments like Visual Studio (this isn't a requirement though you can have .aspx files independent of .cs files). The .cs file defines a class and the class compiled from the .aspx file inherits (or is a sub-type of) this class.

What would be the best way to set up my development box for development?

Again, I don't know about Mono, so I'll give my recommendation based on Microsoft tools. I'd recommend Visual Web Developer 2008 Express. It's available for free has a lot of the great features of the full-blown product and uses the built-in web server which makes configuring your environment less of a hassle.

I'd also recommend the Web Platform Installer. This will help download and install Visual Web Developer 2008 Express and get you up and running quicklu and easily with other things like the .NET Framework, IIS, SQL Server Express and even open source web applications. It's nice an easy to use.

Any general "non-newbieistic" help source apart from MSDN, on getting started with

StackOverflow? :-)

If you're new to .NET I would recommend getting a good grasp on the language first and then ASP.NET specific stuff.

Best .NET books (in my opinion):

ASP.NET resources:

  • Professional ASP.NET 3.5: In C# and VB
  • Scott Hanselman's blog
  • 4GuysFromRolla
  • StackOverflow questions:
    • Learning ASP.NET
    • What are some good resources for learning (Aside from stackoverflow, of course)
    • Where can I Find GOOD ASP.NET tutorial(or books) online?
by anonymous   2017-08-20

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.

by anonymous   2017-08-20

For C#:

  1. CLR via C#
  2. C# in depth from our own nice guy.
by anonymous   2017-08-20

I found that only few developers know about this feature.

If you need a method that works with a value-type variable via some interface (implemented by this value type), it's easy to avoid boxing during the method call.

Example code:

using System;
using System.Collections;

interface IFoo {
    void Foo();
struct MyStructure : IFoo {
    public void Foo() {
public static class Program {
    static void MethodDoesNotBoxArguments<T>(T t) where T : IFoo {
    static void Main(string[] args) {
        MyStructure s = new MyStructure();

IL code doesn't contain any box instructions:

.method private hidebysig static void  MethodDoesNotBoxArguments<(IFoo) T>(!!T t) cil managed
  // Code size       14 (0xe)
  .maxstack  8
  IL_0000:  ldarga.s   t
  IL_0002:  constrained. !!T
  IL_0008:  callvirt   instance void IFoo::Foo()
  IL_000d:  ret
} // end of method Program::MethodDoesNotBoxArguments

.method private hidebysig static void  Main(string[] args) cil managed
  // Code size       15 (0xf)
  .maxstack  1
  .locals init ([0] valuetype MyStructure s)
  IL_0000:  ldloca.s   s
  IL_0002:  initobj    MyStructure
  IL_0008:  ldloc.0
  IL_0009:  call       void Program::MethodDoesNotBoxArguments<valuetype MyStructure>(!!0)
  IL_000e:  ret
} // end of method Program::Main

See Richter, J. CLR via C#, 2nd edition, chapter 14: Interfaces, section about Generics and Interface Constraints.

See also my answer to another question.

by anonymous   2017-08-20

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

by McKenzieG1   2017-08-20

Your first step is to find and understand the parallelism in your problem. It is really easy to write multi-threaded code that performs no better than the single-threaded code it replaces. "Patterns for Parallel Programming" (Amazon) is a great introduction to the key concepts.

Once you have a workable design, start reading the articles in the "Concurrency" topic in the MSDN Magazine archives (link), particularly anything written by Jeff Richter. Those will give you the nuts and bolts stuff on the threading constructs specific to Windows and .NET. (The multi-threading section in Richter's "CLR via C# (Amazon)is short, but very insightful - highly recommended.)