> Chapter 1 - Introduction C# and .NET 6 - 2

AUTHOR: PID-1
TIMESTAMP: 2026-05-31 22:01:52

Getting an Overview of .NET Assemblies

When a *.dll has been created using a .NET compiler, the binary blob is termed an assembly. First, unlike .NET framework assemblies that can be either a *.dll or *.exe, .NET projects are always compiled to a file with a .dll extension, even if the project is an executable. Executable .NET assemblies are executed with the command "dotnet .dll". New in .NET Core 3.0 (and later), the dotnet.exe command is copied to the build directory and renamed to .exe. Running this command automatically calls the "dotnet .dll" file, executing the equivalent of "dotnet .dll". The *.exe with your project name is not actually your projects code; it's a convenient shortcut to running your applications. Second, an assembly contains CIL code, which is conceptually similar to Java bytecode, in that it is not compiled to platform specific instructions until absolutely necessary. Typically "absolutely" necessary is the point at which a block of CIL instructions (sucs as a method implementation) is referenced for use by the .NET runtime. Third, assemblies also contain "metadata" that describes in vivid detail the characteristics of every "type" within the binary. For example, if you have a class named SportsCar, the type metadata describes details such as SportCar's base class, specifies which interfaces are implemented by SportsCar (if any), and gives full descriptions of each member supported by the SportsCar type .NET metadata always present within an assembly and is automatically generated by the language compiler. Finally, in addition to CLI and type metadata assemblies themselves are also described using metadata, which is officially termed a "manifest". The manifest contains information about the current version of the assembly, culture information (used for localizing string and image resources), and a list of all externally referenced assemblies that are required for proper execution. CIL, is a language that sits above any particular platform-specific instruction set.

Compiling CIL to Platform-Specific Instructions

Because assemblies contain CIL instructions rather than platform specific instructions, CIL code must be compiled on the fly before use. The entity that compiles CIL code into meaningful CPU instructions is a JIT compiler, which sometimes goes by the friendly name of jitter. The .NET runtime environment leverages a JIT compiler for each CPU targeting the runtime, each optimized for the underlying platform. As a given jitter compiles CIL instructions into corresponding machine code, it will cche the results in memory in a manner suited to the target OS. In this way, if a call is made to amethod named PrintDocument(), the CIL instructions are compiled into platform-specific instructions on the first invocation and retained in memory for later use. Therefore, the next time PrintDocument() is called, there is no need to recompile the CIL.

Precompiling CIL to Platform-Specific Instructions

There is a utility in .NET called "crossgen.exe", which can be used to pre-JIT your code.

Understanding the Common Type System

CTS is a formal specification that documents how types must be defined in order to be hosted by the .NET runtime. A given assembly may contain any number of distinct types. In the world of .NET, "type" is simply a general term used to refer to a member from the set {class,interface,structure,enumeration,delegate}. CTS Class Types In C#, classes are declared using the "class" keyword.

//A class with 1 method 
class Calc { 
    public int Add(int addend1,int addend2){ 
        return addend1+addend2; 
    } 
}
CTS Interface Types Interfaces are nothing more than a named collection of abstract member definitions and/or default implementations, which are implemented by a given class or structure. In C#, interface types are defined using the "interface" keyword. By convention, all .NET interfaces begin with a capital letter "I", for example:

public interface IDraw { 
    void Draw(); 
}
CTS Structure Types A structure can be thought of as a lightweight class type having value-based entities.

// A C# Structure Type 
struct Point { 
    // structures can contain fields. 
    public int xPos,yPos; 

    // structures can contain parameterized constructors 
    public Point(int x,int y){ 
        xPos = x; 
        yPos = y; 
    } 

    // structures may defined methods. 
    public void PrintPosition(){ 
        Console.WriteLine("Struct"); 
    } 
}
CTS Enumeration Types Enumerations are a handy programming construct that allow you to group name-value pairs.

// A C# enumeration type. 
enum CharacterTypeEnum { 
    Wizard=100, 
    Fighter=200, 
    Thief=300 
}
CTS Delegate Types Delegates are the .NET equivalent of a type-safe, C-style function pointer. The key difference is that .NET delegate is a class that derives from System.MulticastDelegate, rather than a simple pointer to a raw memory address. In C#, delegates are declared using the "delegate" keyword.

// This C# delegate type can "point to" any method returing an int and taking 2 int as input. 
delegate int BinaryOp(int x,int y); 
Bunker_Asset

Intrinsic CTS Data Types

All .NET language keywords ultimately resolve to the same CTS type defined in an assembly named "mscorlib.dll". CTS DATA TYPE C# Keyword System.Boolean bool System.Decimal decimal System.String string System.Char char System.Byte byte System.Sbyte sbyte System.Int16 short System.Int32 int System.Int64 long System.UInt16 ushort System.UInt32 uint System.UInt64 ulong System.Single float System.Double double System.Object object

Understanding the Common Language Specification

As you are aware, different languages express the same programming constructs in unique, language specific terms. For ex, in C# you denote string concatenation using the plus operator (+) while in VB you typically make use of the amperasand (&). The CLS is a set of rules that describe in vivid deetail the minimal and complete set of features a given .NET compiler must support to product code that can be hosted by the .NET Runtime, while at the same time be accessed in a uniform manner by all languages that target the .NET platform. In many ways, the CLS can be viewed as a subset of the full functionality defined by the CTS. An intimate understanding of the CTS and CLS specifications is typically of interest only to tool/compiler builders.

Intrinsic CTS Data Types

You can instruct the C# compiler to check your coode for CLS compliance using a single .NET attribute.

// Tell the C# compiler to check for CLS compliance
[assembly: CLSCompliant(true)]
namespace ConsoleApp1
{
    
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.ReadKey();
        }
    }
    
}
<< RETURN_TO_ROOT