Chapter 0 c# vs .net

C# vs .NET

C# is a programming language, while .NET is a framework. It consists of a run-time environment (CLR) and a class library that we use for building applications.

CLR

When you compile an application, C# compiler compiles your code to IL (Intermediate Language) code. IL code is platform agnostics, which makes it possible to a take a C# program on a different computer with different hardware architecture and operating system and run it. For this to happen, we need CLR. When you run a C# application, CLR compiles the IL code into the native machine code for the computer on which it is running. This process is called Just-in-time Compilation (JIT).

Architecture of .NET Applications

In terms of architecture, an application written with C# consists of building blocks called classes. A class is a container for data (attributes) and methods (functions). Attributes represent the state of the application. Methods include code. They have logic. That's where we implement our algorithms and write code.

A namespace is a container for related classes. So as your application grows in size, you may want to group the related classes into various namespaces for better maintainability.

As the number of classes and namespaces even grow further, you may want to physically separate related namespaces into separate assemblies. An assembly is a file (DLL or EXE) that contains one or more namespaces and classes. An EXE file represents a program that can be executed. A DLL is a file that includes code that can be re-used across different programs.

c# Background

When applications are created, they are created according to the architecture of the physical machine. When compiler compiles the code, it compiles to the machine's native code. So, when an application is written/developed for windows x86 architecture, it doesnt work on other platforms or OS. So, to overcome this, microsoft came up with what java did, when creating c# language.

code which is compiled from c# is translated into an intermediatory system called IL code, or intermediate language code. This IL code translates the code to native application, if it is x86, translate to x86, x64 to x64. CLR sits on memory, and translates IL code to native code. This process is called Just in time compilation.

Namespace is container for related classes. Assembly is container for namespaces. It can be a dll or EXE. When you compile an application, compiler builds one or more assemblies.

Last updated