C# Journal September 2026

CLR provide essential runtime services such as automatic memory management and exception handling. Runtime can be shared by other managed programming languages, such as F#, Visual Basic, and Managed C++.

Past Journal

C# Common Language Runtime

CLR provide essential runtime services such as automatic memory management and exception handling. Runtime can be shared by other managed programming languages, such as F#, Visual Basic, and Managed C++.

  • C# is called managed language because it compiles source code into managed code, which is represented in Intermediate Language (IL).
  • The CLR converts the IL into the native code of the machine, sucs as X64 or X86, usually just prior to execution (Just in Time Compilation).

Constants C#, Brief Explanation

A constant is evaluated statically at compile time, and the compiler literally substitutes its value whenever used.

A constant can serve similar role to a static readonly field, but it is more restrictive. A constant also differ from a static readonly field in that the evaluation of the constant occurs at compile time.

Constant:

public static double Circumference (double radius) {
return 2 * System.Math.PI * radius;
}

static readonly:

static readonly DateTime StartupTIme = DateTime.Now;

C# Boxing and Unboxing

Boxing: Act of converting a value type instance to a reference type instance.

Example:

int x = 9;

object obj = x;

Unboxing: Reverses the operation by casting the object back to the original value type:

Example:

int y = (int)obj;

Unboxing requires an explicit cast. The runtime checks that the stated value type matches the actual object type, and throws an InvalidCastException if the check fails.

Boxing copies the value type instance into the new object, and unboxing copies the contents of the object back into a value type instance.

C# Compilation

The C# compiler compiles source code (a set of files with .cs extension) into an assembly.

  • An assembly is the unit of packaging and deployment in .NET.
  • An assembly can be either an application or library.
  • .NET itself is a set of libraries (as well as runtime environment)

.NET 8 assemblies never have a .exe extension. The .exe after building a .NET 8 application is a platform spesific native loader responsible for starting application .dll assembly

C# Delegates

A delegate is an object that know how to call a method.

A delegate is similar to a callback, a general term that captures construcs such as C function pointers.

A delegate design might be a better choice than an interface design if one or more of these conditions are true:

  • The interfac defines only a single method
  • Multicast capability is needed
  • The subscriber needs to implement the interface multiple times

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *