Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

C# Tutorial

C# HOME C# Intro C# Get Started C# Syntax C# Output C# Comments C# Variables C# Data Types C# Type Casting C# User Input C# Operators C# Math C# Strings C# Booleans C# If...Else C# Switch C# While Loop C# For Loop C# Break/Continue C# Arrays

C# Methods

C# Methods C# Method Parameters C# Method Overloading C# Scope C# Recursion

C# Classes

C# OOP C# Classes/Objects C# Class Members C# Constructors C# this Keyword C# Access Modifiers C# Properties C# Static C# Inheritance C# Polymorphism C# Abstraction C# Interface C# Enums C# Structs

C# Errors

C# Errors C# Debugging C# Exceptions

C# Data Structures

C# Data Structures C# List C# Dictionary C# HashSet C# Stack C# Queue

C# Advanced

C# Files C# Date and Time C# Nullable Types C# Generics C# Lambda C# LINQ

C# Cert

C# Certificate

C# How To

C# How Tos

C# Examples

C# Examples C# Compiler C# Exercises C# Quiz C# Practice Problems C# Server C# Syllabus C# Study Plan


C# Get Started


Share

C# IDE

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

An IDE (Integrated Development Environment) is a program where you write, run and fix your code.

In this tutorial, we use Visual Studio Community. It is free, and it is made by Microsoft, the company that also makes C# and .NET. You can download it from https://visualstudio.microsoft.com/vs/community/.


C# Install

Follow these steps to install Visual Studio and create your first C# program:

  1. Download and run the Visual Studio Installer.
  2. Choose the .NET desktop development workload, and click Install.
  3. When the installation is complete, click Launch to start Visual Studio.
  4. On the start window, choose Create a new project.
  5. Choose Console App (the one with the C# tag) from the list, and click Next.
  6. Enter a name for your project, for example HelloWorld, and click Next.
  7. Choose the newest .NET version in the Framework list, check the box Do not use top-level statements, and click Create.

Visual Studio creates a file called Program.cs. 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 »

Visual Studio may write internal class Program and leave out the using System; line. That is fine: the program works the same way.

Don't worry if you don't understand the code above. We will explain it in the next chapters. For now, focus on how to run the code.

Run the program by pressing F5 on your keyboard (or click the green Start button at the top). Visual Studio compiles and runs your code, and opens a window that shows the result:

Hello World!

The window also shows a line that ends with "exited with code 0". This means that the program finished without errors. Press any key to close the window.

Congratulations! You have now written and run 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 »


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.