CLR via C#, Second Edition (Developer Reference)

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

CLR via C#, Second Edition (Developer Reference)


Review Date:


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:

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

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.

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.)