Introduction to C# and .NET Framework

C#


C# (pronounced "C sharp") is a modern, high-level programming language developed by Microsoft. It's designed for building a wide range of applications, from desktop software to web applications and games.


Think of C# as a programming language, like a set of rules that computers understand. Just like how people use different languages to communicate, computers use programming languages like C# to understand what to do.


C# is object-oriented, meaning it's organized around the idea of objects that contain both data and the functions that can operate on that data.

 

Here is a simple C# program-


using System;


namespace MyClassGroup

{

    class MyClass

    {

        // Data

        public string message = "Hello, World!";


        // Function

        public void PrintHello()

        {

            Console.WriteLine(message);

        }

    }

}


Let’s break down what's happening in this program:

  • We're using the using System; directive to include the System namespace, which contains the Console class for input and output operations. 

  • Inside MyClassGroup namespace, We create a Class named MyClass.

  • Inside the Class, we declare a variable message of type string to store the "Hello, World!" text.

  • We define a function called PrintHello which doesn't take any arguments (parameters).

  • We use the Console.WriteLine function to display the content of the message variable on the console.



.NET


.NET(pronounced "Dot Net") is a software development framework developed by Microsoft. It provides a platform for building, deploying, and running applications. It includes a collection of libraries, tools, and runtime environments that help developers create different types of software.


Think of .NET as a toolbox or a set of tools that helps programmers build software more easily. It's like a collection of pre-made parts that you can use to build things faster. .NET includes lots of useful stuff, like tools to help with security, database handling, and more.


.NET supports multiple programming languages, including C#, and offers features like memory management, security, and interoperability between different languages and platforms.


Here are the 2 main components of .NET framework- 

  1. Class Library: 

The Class Library is a collection of pre-built, reusable code components (classes) that cover a wide range of functionalities. It provides ready-made solutions for common programming tasks, like file handling, networking, data manipulation, and more. Developers can use these classes to save time and effort by not having to create these functionalities from scratch. In the previous program, the System namespace provides the Console class and the Console.WriteLine() method, which is fundamental for displaying output to the console.

  1. Common Language Runtime (CLR):

The Common Language Runtime is the execution engine of the .NET framework. It manages the execution of .NET applications, including memory management (garbage collection), code execution, security enforcement, and exception handling. The CLR ensures that code written in different .NET languages can work together by compiling them into an intermediate language (IL) that the CLR can execute. In simple terms, the Class Library offers a toolbox of pre-built tools, and the CLR is the engine that runs and manages the tools, making the .NET framework a powerful and efficient platform for building and running software.


C# VS .NET 


C#

.NET

C# is a programming language developed by Microsoft.

.NET is a development framework provided by Microsoft.

C# provides the syntax and rules for writing code.

.NET includes libraries, runtime environments (like CLR), and tools that support various programming languages (including C#).

C# includes features like classes, objects, inheritance, and other object-oriented programming concepts.

.NET offers a vast collection of pre-built classes for common tasks like file handling, networking, and more.

C# code is compiled into intermediate language (IL) code, which is executed by the common language runtime (CLR).

Part of .NET, the CLR manages memory, handles security, and executes code written in various languages, including C#.

 

The main difference is that C# is a language used to write instructions for computers, while .NET is a collection of tools and libraries that help those instructions work better and do more cool things. C# is like the words you use to tell a computer what to do, and .NET is like the handy tools you use to build those things. They often go together – C# to write the code and .NET to make it work smoothly.

.NET Application

Class is a container that has some Data also called Attributes and Methods also called Functions.

Data represent the state of the application. Methods execute codes and do some actions.


Namespace is a container for related classes.


An Assembly is a container for related namespaces. It’s a physical file on disk which can either be a dll(Dynamic Link Library)  or exe(Executable).


.NET Application is simply a group of Assemblies.