> 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 "dotnetCompiling 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);
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 objectUnderstanding 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();
}
}
}