- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Arithmetic Operators
- C# - Assignment Operators
- C# - Relational Operators
- C# - Logical Operators
- C# - Bitwise Operators
- C# - Miscellaneous Operators
- C# - Operators Precedence
- C# Conditional Statements
- C# - Decision Making
- C# - If
- C# - If Else
- C# - Nested If
- C# - Switch
- C# - Nested Switch
- C# - Switch Expressions
- C# Control Statements
- C# - Loops
- C# - For Loop
- C# - While Loop
- C# - Do While Loop
- C# - Nested Loops
- C# - Break
- C# - Continue
- C# - Foreach Loop
- C# - Goto Statement
- C# OOP & Data Handling
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - LINQ
- C# - IEnumerable vs IEnumerator
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Tasks and Parallel Programming
- C# - Multithreading
- C# - Extension Methods
C# Tutorial
Introduction to C#
C# (pronounced "C-Sharp") is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. It is widely used for the following:
- Web Development (ASP.NET)
- Desktop Applications (Windows Forms, WPF)
- Game Development (Unity)
- Cloud & AI Applications
Write, Compile, & Run C# Code Instantly
Our C# tutorial allows you to execute code inline without leaving the page unlike other sites. Learn C# hands-on with real-time coding experience right here!
Main features of this tutorial:
- Best for Beginners & Experienced Developers
- Covers Basic to Advanced Topics
- Interactive Compilation - No Setup Needed!
Click the Edit & RUN
button to RUN or EDIT this code.
using System;
class Program{
static void Main(string[] args){
Console.WriteLine("Welcome to TutorialsPoint");
}
}
Why Learn C#?
- Versatile Used in Web, Mobile, and Game Development
- Easy to Learn Similar to Java & C++
- Powerful & Secure Type-safe and managed by the .NET runtime
Getting Started with C#
To run C# programs, you need the following tools:
- .NET SDK (Download from dotnet.microsoft.com)
- A Code Editor (VS Code, Visual Studio, or any online compiler)
But wait! You dont need to install anything. Run the examples below right here in our tutorial!
First C# Program "Hello, World!"
Run This Code Instantly by clicking Edit & Run button!
using System;
class Program
{
static void Main(string[] args)
{
// Tp print "Hello, World!"
Console.WriteLine("Hello, World!");
}
}
Explanation:
-
using System;Imports System namespace for basic functions -
class ProgramDefines a class named Program -
static void Main()Entry point of the program -
Console.WriteLine()Prints text to the console
C# Syntax & Basics
C# programs follow a structured format. Heres an example with variables, data types, and user input:
Test the code below by clicking Edit & Run button! You can modify the values and run the code to practice well.
using System;
class Program
{
static void Main()
{
int age = 25;
string name = "Alice";
Console.WriteLine("Name: " + name);
Console.WriteLine("Age: " + age);
}
}
C# Variables & Data Types
Data Types in C#
| Type | Size | Example |
|---|---|---|
| int | 4 bytes | int x = 100; |
| double | 8 bytes | double pi = 3.14; |
| char | 2 bytes | char letter = 'A'; |
| string | Varies | string name = "C#"; |
| bool | 1 byte | bool isAlive = true; |
Try the Example Below!
using System;
class Program
{
static void Main()
{
double price = 99.99;
bool isAvailable = true;
Console.WriteLine("Price: $" + price);
Console.WriteLine("In Stock: " + isAvailable);
}
}
Modify values & test!
C# Control Statements
Control flow statements help in decision-making and looping.
If-Else Statement
Run This Conditional Check!
using System;
class Program
{
static void Main()
{
Console.Write("Enter your age: ");
int age = Convert.ToInt32(Console.ReadLine());
if (age >= 18)
Console.WriteLine("You are eligible to vote!");
else
Console.WriteLine("Sorry, you must be 18+ to vote.");
}
}
Modify values & test!
Loops in C#
C# supports various loops:
| Loop Type | Usage |
|---|---|
| for loop | Known number of iterations |
| while loop | Repeats while condition is true |
| do-while loop | Runs at least once |
Try a Simple Loop:
using System;
class Program
{
static void Main()
{
for (int i = 1; i <= 5; i++)
{
Console.WriteLine("Iteration: " + i);
}
}
}
Modify the loop condition and see what happens!
C# Functions & Methods
Functions in C# allow code reusability.
Run This Function Example
using System;
class Program
{
static void Greet(string name)
{
Console.WriteLine("Hello, " + name + "!");
}
static void Main()
{
Greet("Alice");
Greet("Bob");
}
}
Modify the function call with different names!
OOP in C# (Classes & Objects)
C# is object-oriented, meaning it uses classes & objects.
Create & Use Objects
using System;
class Car
{
public string Brand;
public void ShowBrand()
{
Console.WriteLine("Car Brand: " + Brand);
}
}
class Program
{
static void Main()
{
Car myCar = new Car();
myCar.Brand = "Tesla";
myCar.ShowBrand();
}
}
Change Brand and see different outputs!
C# File Handling (Read & Write)
Read & Write Files in C#. Try this code on your local computer.
using System;
using System.IO;
class Program
{
static void Main()
{
File.WriteAllText("test.txt", "Hello, C#!");
string content = File.ReadAllText("test.txt");
Console.WriteLine("File Content: " + content);
}
}
This will create a file called test.txt in your local directory. Check the content of the file.
Why Learn C# with Us?
- Best Structured Tutorials Covers all levels
- Inline Code Compilation No need to leave the page!
- Practical Real-World Examples Hands-on learning
Who Should Learn C#?
C# is perfect for beginners, software developers, game developers, and enterprise professionals. Whether you're building Windows applications, web apps, mobile apps (Xamarin), Unity games, or AI solutions, C# is a versatile and powerful language.
- Beginners & Students Easy-to-learn syntax, strong OOP foundation
- Software & Web Developers Ideal for .NET, ASP.NET, and full-stack development
- Game Developers Primary language for Unity 3D
- Mobile Developers Build cross-platform apps with Xamarin
- AI & Machine Learning C# supports ML.NET for AI applications
Start learning C# today and unlock endless opportunities in tech!
Prerequisites to Learn C#
C# is beginner-friendly, but having some basic knowledge can make learning easier:
- Basic Understanding of Programming Concepts (Optional but helpful)
- Familiarity with Any Programming Language (C, C++, Java, or Python)
- Logical Thinking & Problem-Solving Skills
- Basic Knowledge of OOP (Object-Oriented Programming) (Recommended)
- A Computer with .NET SDK & a Code Editor (Visual Studio, VS Code, or an online compiler)
No prior coding experience? No worries! Our tutorial covers everything from scratch.