The Best Way to learn any language or a technology is to learn it by development projects in it. In C# we can do project base learning is variety of different application framework!
The Architecture of Visual C# Project is shown below;
C# programs run on the .NET Framework, an integral component of Windows that includes a virtual execution system called the common language runtime (CLR) and a unified set of class libraries. The CLR is the commercial implementation by Microsoft of the common language infrastructure (CLI), an international standard that is the basis for creating execution and development environments in which languages and libraries work together seamlessly.
Source code written in C# is compiled into an intermediate language (IL) that conforms to the CLI specification. The IL code and resources, such as bitmaps and strings, are stored on disk in an executable file called an assembly, typically with an extension of .exe or .dll. An assembly contains a manifest that provides information about the assembly’s types, version, culture, and security requirements.
When the C# program is executed, the assembly is loaded into the CLR, which might take various actions based on the information in the manifest. Then, if the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions. The CLR also provides other services related to automatic garbage collection, exception handling, and resource management. Code that is executed by the CLR is sometimes referred to as “managed code,” in contrast to “unmanaged code” which is compiled into native machine language that targets a specific system. The following diagram illustrates the compile-time and run-time relationships of C# source code files, the .NET Framework class libraries, assemblies, and the CLR.
Language interoperability is a key feature of the .NET Framework. Because the IL code produced by the C# compiler conforms to the Common Type Specification (CTS), IL code generated from C# can interact with code that was generated from the .NET versions of Visual Basic, Visual C++, or any of more than 20 other CTS-compliant languages. A single assembly may contain multiple modules written in different .NET languages, and the types can reference each other just as if they were written in the same language.
In addition to the run time services, the .NET Framework also includes an extensive library of over 4000 classes organized into namespaces that provide a wide variety of useful functionality for everything from file input and output to string manipulation to XML parsing, to Windows Forms controls. The typical C# application uses the .NET Framework class library extensively to handle common “plumbing” chores.
Let start it by simplest way sort of application. Known as Console Application.
Create a C# Console Project in Microsoft Visual Studio.
Under C# -> Windows -> Classic Desktop;
And from here, create the project with Name ‘HelloConsole”;
As Soon you’ll click ‘OK’ to create a project, you’ll get a screen like here;
As you see in the ‘Solution Explorer the Project is part of Solution. So as soon you’ll create a project, you’ll create both the project and the solution. You can also add multiple project in a one solution.
As you observe, Visual Studio has created some code for you, that help you to easily write your code and customize it according to your own.
A Console Application initially consists of single C# class. Under the namespace each class is a member. So within a namespace, there’s a class. The Default name of starting class in a console application is always ‘Program’. And that has something called the Main Method! Any code you place inside the Main Method excited automatically as the Application starts up! Those’re the rules for console application. The rules are different for other languages. i.e. rules will be different for ASP.NET for the Web, Win-Forms or WPF for the desktop or the other application frameworks!
To Say Hello World in a console application lets write something in Main Method. The Main Method always execute automatically at the runtime.
So to output something in a Console, type the word ‘Console’. (Visual Studio would really help you through IntelliSense on your every part of the code). As we’re trying to write something. So can WriteLine method from Console pre-defined class. And Pass the Message through Parameter;
Console.WriteLine(“Hello, Console World”);
Now Run the Application. At this moment, the project will build and console screen arrive and on the very next moment the console will disappear and Application will stop! Perhaps if you will Run it without Debugging only then it will show the correct output.
Here’s the way to build that kind of functionality in the application itself. So now use the Console class and call ReadKey method from it;
So when now we run the application, it will show us the output but this the Console Screen will pause and waiting for the Input!
So that’s how you can easily develop a C# Console Project.