BEST SITE FOR WEB DEVELOPERS
C# Language. W3Schools lessons in English

Ua Es De

C# Get Started


C# IDE

The easiest way to get started with C#, is to use an IDE.

An IDE (Integrated Development Environment) is used to edit and compile code.

In our tutorial, we will use Visual Studio Community, which is free to download from https://visualstudio.microsoft.com/vs/community/.

Applications written in C# use the .NET Framework, so it makes sense to use Visual Studio, as the program, the framework, and the language, are all created by Microsoft.


C# Install

Once the Visual Studio Installer is downloaded and installed, choose the .NET workload and click on the Modify/Install button:

Workload C#

After the installation is complete, click on the Launch button to get started with Visual Studio.

On the start window, choose Create a new project:

New Project C#

Then click on the "Install more tools and features" button:

New Project C-Sharp

Choose "Console App (.NET Core)" from the list and click on the Next button:

Console App C#

Enter a name for your project, and click on the Create button:

Save As C#

Visual Studio will automatically generate some code for your project:

Program C#

The code should look something like this:

Program.cs

using System;

namespace HelloWorld
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");
    }
  }
}
Try it Yourself »

Don't worry if you don't understand the code above — we will discuss it in detail in later chapters. For now, focus on how to run the code.

Run the program by pressing the F5 button on your keyboard (or click on "Debug" -> "Start Debugging"). This will compile and execute your code. The result will look something to this:

Hello World!
C:\Users\Username\source\repos\HelloWorld\HelloWorld\bin\Debug\netcoreapp3.0\HelloWorld.exe (process 13784) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window...

Congratulations! You have now written and executed your first C# program.


Learning C# At W3Schools

When learning C# at W3Schools.com, you can use our "Try it Yourself" tool, which shows both the code and the result. This will make it easier for you to understand every part as we move forward:

Program.cs

using System;

namespace HelloWorld
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");
    }
  }
}

Result:

Hello World!

Try it Yourself »


Code editors and IDEs for writing code in C#

Any code editor that supports the C# language can be used to write code in the C# (C-Sharp) programming language. However, for more efficient work, programmers usually use integrated development environments (IDEs), which provide additional features such as code autocompletion, intelligent debugging, and project management.

Here are some popular code editors and IDEs for C#:

  • Visual Studio - is the most popular IDE for C# developed by Microsoft. Visual Studio includes a wide range of features, such as support for different programming languages, debugging, project management, and creating visual user interface elements. Visual Studio Code is a powerful and flexible code editor developed by Microsoft. Visual Studio Code supports many programming languages, including C#.
  • JetBrains Rider - is a C# IDE developed by JetBrains. Rider offers a wide range of features, including support for various programming languages, debugging, project management, and creating visual user interface elements.
  • Eclipse - is an open-source development environment that supports many programming languages, including C#.
  • MonoDevelop - is an open-source development environment that supports many programming languages, including C#.

To program in C#, you need to install the C# compiler on your computer. The C# compiler converts C# source code into machine code that can be executed on a computer.

The C# compiler is part of the .NET Framework, which can be downloaded from the web Microsoft site.

In addition to the C# compiler, you may also need to install other programs such as:

  • Visual Studio or another IDE for C#
  • A code editor such as Visual Studio Code or JetBrains Rider
  • A debugging tool such as Visual Studio Debugger or MonoDevelop Debugger
  • A debugging tool such as Visual Studio Profiler or MonoDevelop Profiler

Exactly which set of programs you will need depends on your specific needs and tasks.


An anecdote about C# and Python programmers

Two programmers - one in C# and the other - a Python programmer, argued about who is the better programmer. The first of them said: "I'm such a cool programmer that I can write a C# program that will do any task using only one line of code!"

The Python programmer said, "It's impossible! If you can do it, I'll buy you lunch at the best restaurant in town."

The first programmer started thinking and finally wrote a single line of code in C#. He launched it and the program worked!

The second programmer was very surprised and asked: "How did you manage to write such a complex program in one line?"

The first programmer smiled and said, "I just wrote 'while(true);' is an endless loop that does nothing. But it really does any task!"