Introduction To C#
Introduction To C#
Click the Edit & RUN button to RUN or EDIT this code.
Open Compiler
using System;
class Program{
static void Main(string[] args){
Console.WriteLine("Welcome to TutorialsPoint");
}
}
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!
Open Compiler
using System;
class Program
{
static void Main(string[] args)
{
// Tp print "Hello, World!"
Console.WriteLine("Hello, World!");
}
}
Explanation:
Test the code below by clicking Edit & Run button! You can modify the values and run the
code to practice well.
Open Compiler
using System;
class Program
{
static void Main()
{
int age = 25;
string name = "Alice";
Open Compiler
using System;
class Program
{
static void Main()
{
double price = 99.99;
bool isAvailable = true;
C# Control Statements
Control flow statements help in decision-making and looping.
If-Else Statement
Open Compiler
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.");
}
}
Loops in C#
Open Compiler
using System;
class Program
{
static void Main()
{
for (int i = 1; i <= 5; i++)
{
Console.WriteLine("Iteration: " + i);
}
}
}
Open Compiler
using System;
class Program
{
static void Greet(string name)
{
Console.WriteLine("Hello, " + name + "!");
}
Open Compiler
using System;
class Car
{
public string Brand;
class Program
{
static void Main()
{
Car myCar = new Car();
myCar.Brand = "Tesla";
myCar.ShowBrand();
}
}
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.
Prerequisites to Learn C#
C# is beginner-friendly, but having some basic knowledge can make learning easier:
No prior coding experience? No worries! Our tutorial covers everything from scratch.