GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Technologies
  • Databases
  • Computer Programming
  • Web Development
  • Java Technologies
  • Computer Science
  • Mobile Development
  • Big Data & Analytics
  • Microsoft Technologies
  • DevOps
  • Latest Technologies
  • Machine Learning
  • Digital Marketing
  • Software Quality

This view

  • Original page
  • New address

GeezerVison is showing www.tutorialspoint.com — C# Tutorial

Csharp Tutorial
  • 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# - Custom Exceptions
  • 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# - Lambda Expressions
  • C# - Async and Await
  • C# Modern Features
  • C# - Tuples
  • C# - Records
  • C# - Pattern Matching Enhancements
  • C# - Top-level Statements
  • C# - Nullable Reference Types
  • C# - What's New in C# 11 / 12 / 13
  • C# - Global Usings
  • C# - File-Scoped Namespaces
  • C# Practical & Advanced Usage
  • C# - JSON & XML Handling
  • C# - Data Serialization & Deserialization
  • C# - REST API Calls with Httpclient
  • C# - Dependency Injection
  • C# - Unit Testing with NUnit, xUnit & MSTest
  • C# - Package Management with NuGet
  • C# Useful Resources
  • C# - Developer's AI Tools
  • C# - Questions and Answers
  • C# - Cheatsheet
  • C# - Quick Guide
  • C# - Useful Resources
  • C# - Discussion
  • C# - Online Compiler
Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Online Resume Builder
  • HR Interview Questions
  • Computer Glossary
  • Who is Who
C# Tutorial

C# Tutorial

PDF Version Quick Guide Resources Discussion

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 run button 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:

  1. using System; Imports System namespace for basic functions
  2. class Program Defines a class named Program
  3. static void Main() Entry point of the program
  4. 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.

Tutorix - AI Tutor
Previous Next
Advertisements
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.