C#
v5.0.201
C#
v5.0.201
C# is a statically typed, multi-paradigm language created by Microsoft under Anders Hejlsberg, first released in 2002 alongside the .NET platform. It combines object-oriented and functional features with strong typing, automatic memory management, and a modern syntax. C# compiles to intermediate language that runs on the .NET runtime, giving it portability and just-in-time performance.
Today C# is used for web backends with ASP.NET Core, desktop apps, cloud services on Azure, and game development with Unity. The language has evolved rapidly, adding async/await, pattern matching, records, and nullable reference types. This compiler runs on the .NET SDK reporting version 5.0.201, so you can write modern C# programs and use the extensive .NET base class library.
using System;
class Program {
static void Main() {
Console.WriteLine("Hello, World!");
}
}using System;
class Program {
static void Main() {
string name = Console.ReadLine();
Console.WriteLine($"Hello, {name}!");
}
}using System;
using System.Collections.Generic;
class Program {
static void Main() {
var fruits = new List<string> { "apple", "banana", "cherry" };
foreach (var fruit in fruits) {
Console.WriteLine(fruit);
}
}
}using System;
class Program {
static long Factorial(int n) => n <= 1 ? 1 : n * Factorial(n - 1);
static void Main() {
Console.WriteLine(Factorial(5));
}
}using System;
class Program {
static void Main() {
try {
int x = int.Parse("abc");
Console.WriteLine(x);
} catch (FormatException e) {
Console.WriteLine("Invalid number: " + e.Message);
} finally {
Console.WriteLine("Done");
}
}
}using System;
using System.Collections.Generic;
class Program {
static void Main() {
var counts = new Dictionary<char, int>();
foreach (char c in "banana") {
counts[c] = counts.GetValueOrDefault(c, 0) + 1;
}
foreach (var kv in counts) {
Console.WriteLine($"{kv.Key}: {kv.Value}");
}
}
}using System;
using System.Linq;
class Program {
static void Main() {
int[] nums = { 3, 1, 4, 1, 5 };
var sorted = nums.OrderBy(n => n).ToArray();
Console.WriteLine(string.Join(", ", sorted));
Console.WriteLine("Sum: " + nums.Sum());
}
}using System;
class Person {
public string Name { get; set; }
public int Age { get; set; }
public string Describe() => $"{Name} ({Age})";
}
class Program {
static void Main() {
var p = new Person { Name = "Ada", Age = 36 };
Console.WriteLine(p.Describe());
}
}using System;
record Point(int X, int Y);
class Program {
static string Describe(Point p) => p switch {
(0, 0) => "origin",
var (x, y) => $"({x}, {y})"
};
static void Main() {
Console.WriteLine(Describe(new Point(0, 0)));
Console.WriteLine(Describe(new Point(2, 3)));
}
}using System;
class Program {
static void Main() {
string? maybe = null;
int len = maybe?.Length ?? -1;
Console.WriteLine(len);
}
}Yes. CompileBytes compiles and runs C# in your browser, so no local .NET SDK installation is required.
It runs on the .NET SDK reporting version 5.0.201, so you can use C# 9 features such as records and pattern matching.
Use Console.ReadLine() in your code and type the values into the stdin box before running the program.
Yes, compiling and running C# on CompileBytes is free with no account needed.
On this SDK you can use the classic Program class with Main; top-level statements were introduced in C# 9 and may also work depending on project setup.