My Account Subscribe Help About
Sign In | Register FREE
Friday, April 10, 2026
Man jailed for killing abused wife who jumped from bridgeCeasefire or no ceasefire, the Middle East's reshuffling is not yet doneMelania Trump denies ties to Jeffrey Epstein and urges hearing for survivorsSimple guide: How the Iran war is affecting the cost of holidays, food and clothesEU fingerprint and photo travel rules come into forceWant to help garden birds? Don't feed them in warmer months, says RSPBDublin Airport issues travel guidance as Irish fuel protests continueMen behind 'Tripadvisor for people smugglers' jailed for 19 yearsIran conflict must be 'line in sand' to build more resilient UK, Starmer saysBafta fell short in duty of care when racial slur was shouted, review findsExtra £5m pledged for patrolling places of worship'Endless fears': Even if fighting stops, the damage to Iran's children will endureLebanon thought there was a ceasefire - then Israel unleashed deadly blitzHow many ships are crossing the Strait of Hormuz?Has US achieved its war objectives in Iran?Can stats help you find the Grand National winner?This coat cost $248 in illegal tariffs. Will he ever get the money back?From a smuggled harmonica to Artemis' playlist - the history of music in spaceWeekly quiz: What might have made Paddington panic about his marmalade?How the Artemis crew will splash down on EarthLeBron and Bronny James record first son-to-father assist in NBA historyTen cases a day - 'blitz courts' could tackle the Crown Court backlog'I was in a slump - now my art is in Billie Eilish's house'Labrinth not involved in Euphoria's third seasonLava soars into air as Hawaii's Kilauea volcano erupts againWhite House staff told not to place bets on prediction marketsRussia and Ukraine agree to truce for Orthodox EasterBBC News appIs Defence Secretary Pete Hegseth waging a holy war against Iran?Defence secretary interview on Russian submarine operation
FDN » .NET Framework » C# Language Primer

C# Language Primer

C# Language Primer

C# (pronounced "C sharp") is the flagship language of the .NET Framework. It combines the power of C++ with the productivity of Visual Basic.

Hello World

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, Flamenet Developer Network!");
    }
}

Classes and Objects

public class Employee
{
    // Fields
    private string _firstName;
    private string _lastName;

    // Properties
    public string FirstName
    {
        get { return _firstName; }
        set { _firstName = value; }
    }

    public string LastName
    {
        get { return _lastName; }
        set { _lastName = value; }
    }

    public string FullName
    {
        get { return _firstName + " " + _lastName; }
    }

    // Constructor
    public Employee(string firstName, string lastName)
    {
        _firstName = firstName;
        _lastName = lastName;
    }

    // Method
    public override string ToString()
    {
        return FullName;
    }
}

// Usage
Employee emp = new Employee("John", "Smith");
Console.WriteLine(emp.FullName);  // "John Smith"

Data Types

C# Type.NET TypeDescription
intSystem.Int3232-bit integer
longSystem.Int6464-bit integer
floatSystem.Single32-bit floating point
doubleSystem.Double64-bit floating point
decimalSystem.Decimal128-bit precise (financial)
boolSystem.Booleantrue or false
stringSystem.StringUnicode string (immutable)
objectSystem.ObjectBase type of all types

Control Flow

// if-else
if (age >= 18)
    Console.WriteLine("Adult");
else
    Console.WriteLine("Minor");

// switch
switch (role)
{
    case "admin":
        Console.WriteLine("Administrator");
        break;
    case "mod":
        Console.WriteLine("Moderator");
        break;
    default:
        Console.WriteLine("Member");
        break;
}

// for loop
for (int i = 0; i < 10; i++)
    Console.WriteLine(i);

// foreach
string[] names = { "Alice", "Bob", "Charlie" };
foreach (string name in names)
    Console.WriteLine(name);

// while
while (reader.Read())
    Console.WriteLine(reader["Name"]);

Exception Handling

try
{
    int result = 10 / 0;
}
catch (DivideByZeroException ex)
{
    Console.WriteLine("Error: " + ex.Message);
}
finally
{
    Console.WriteLine("Cleanup code runs always.");
}
« Back to .NET Framework « Back to FDN