18/6/26, 9:29 C# Tutorial
Home Csharp
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 ([Link])
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){
[Link]("Welcome to TutorialsPoint");
}
}
Why Learn C#?
[Link] 1/8
18/6/26, 9:29 C# Tutorial
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 [Link])
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!"
[Link]("Hello, World!");
}
}
Explanation:
using System; Imports System namespace for basic functions
class Program Defines a class named Program
static void Main() Entry point of the program
[Link]() Prints text to the console
C# Syntax & Basics
[Link] 2/8
18/6/26, 9:29 C# Tutorial
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";
[Link]("Name: " + name);
[Link]("Age: " + age);
}
}
C# Variables & Data Types
Data Types in C#
Type Size Example
4
int int x = 100;
bytes
8
double double pi = 3.14;
bytes
2
char char letter = 'A';
bytes
string Varies string name = "C#";
bool 1 byte bool isAlive = true;
Try the Example Below!
[Link] 3/8
18/6/26, 9:29 C# Tutorial
using System;
class Program
{
static void Main()
{
double price = 99.99;
bool isAvailable = true;
[Link]("Price: $" + price);
[Link]("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()
{
[Link]("Enter your age: ");
int age = Convert.ToInt32([Link]());
if (age >= 18)
[Link]("You are eligible to vote!");
else
[Link] 4/8
18/6/26, 9:29 C# Tutorial
[Link]("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++)
{
[Link]("Iteration: " + i);
}
}
}
Modify the loop condition and see what happens!
C# Functions & Methods
Functions in C# allow code reusability.
[Link] 5/8
18/6/26, 9:29 C# Tutorial
Run This Function Example
using System;
class Program
{
static void Greet(string name)
{
[Link]("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()
{
[Link]("Car Brand: " + Brand);
}
[Link] 6/8
18/6/26, 9:29 C# Tutorial
class Program
{
static void Main()
{
Car myCar = new Car();
[Link] = "Tesla";
[Link]();
}
}
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 [Link];
class Program
{
static void Main()
{
[Link]("[Link]", "Hello, C#!");
string content = [Link]("[Link]");
[Link]("File Content: " + content);
}
}
This will create a file called [Link] 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#?
[Link] 7/8
18/6/26, 9:29 C# Tutorial
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, [Link], and full-stack development
Game Developers Primary language for Unity 3D
Mobile Developers Build cross-platform apps with Xamarin
AI & Machine Learning C# supports [Link] 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.
[Link] 8/8