code-playpad

C# (experimental)

language="csharp" compiles C# 14 with the real Roslyn compiler and runs it on the .NET WebAssembly runtime, in a Web Worker. The first Run downloads about 14 MB compressed (40 MB once unpacked); later runs use Cache Storage. Each Run starts fresh, which took about a second on a laptop.

Hello

var names = new List<string> { "Ada", "Grace", "Linus" }; foreach (var name in names) Console.WriteLine($"Hello, {name}!");

Reading stdin

Input is prefilled: edit the stdin box before pressing Run. The program sees the end of input after the last line.

var name = Console.ReadLine(); var count = int.Parse(Console.ReadLine() ?? "0"); for (var i = 1; i <= count; i++) Console.WriteLine($"{i}. hello, {name}");

A practice problem

var solver = new Solver(); Console.WriteLine(string.Join(", ", solver.TwoSum(new[] { 2, 7, 11, 15 }, 9))); class Solver { public int[] TwoSum(int[] numbers, int target) { var seen = new Dictionary<int, int>(); for (var i = 0; i < numbers.Length; i++) { if (seen.TryGetValue(target - numbers[i], out var j)) return new[] { j, i }; seen[numbers[i]] = i; } return Array.Empty<int>(); } }

A compiler error

int answer = "forty-two"; Console.WriteLine(answer);

Stop a runaway loop

Console.WriteLine("Press Stop."); while (true) { }

Limits

An independent project, not affiliated with or endorsed by Microsoft.