Loading…

Online C# Compiler and Playground

Browser-based compiler and playground for C#, Progsity IDE.

About C#

C# is the main language of .NET: desktop software, web backends, and most games built on Unity. It is statically typed like Java, with LINQ for working over collections, properties instead of getters, and a large standard library.

Here your file is compiled by Mono's C# compiler and run on the Mono runtime in a sandbox. That gives you C# 7 and the classic .NET class library: System, System.Linq, System.Collections.Generic and System.Numerics for BigInteger. Newer syntax such as top-level statements or records is not part of this compiler, so keep a class with a static Main.

The judge runs C# on the same toolchain, which makes this a quick place to check a solution before you submit it.

How to use

  1. Keep one class with public static void Main(). The class can have any name.
  2. Type the input in the stdin panel and read it with Console.ReadLine().
  3. Press Run. A compiler error names the line, the column and a CS code you can search for.

FAQ

Which C# version is this?›

C# (Mono 6.8). Mono's compiler supports C# 7: tuples, pattern matching, local functions, string interpolation and async are all there.

Is this .NET 8?›

No. It is Mono, an open implementation of the .NET Framework. Code that sticks to the standard class library runs the same; features added in C# 8 and later do not compile.

Can I use BigInteger?›

Yes. Add using System.Numerics; at the top. The reference is already passed to the compiler.

Can I install NuGet packages?›

No. The sandbox has no network, and a program is one file compiled against the standard library.

Can I save and share my code?›

Yes, once you are signed in. Running code needs no account.

Code examples

Tap “Try this” to load sample code into the editor above.

  • LINQ over an array

    using System;
    using System.Linq;
    
    public class Program
    {
        public static void Main()
        {
            int[] nums = { 3, 1, 4, 1, 5, 9 };
            Console.WriteLine(string.Join(" ", nums.OrderBy(n => n)));
            Console.WriteLine(nums.Where(n => n % 2 == 1).Sum());
        }
    }
  • Read two numbers

    using System;
    
    public class Program
    {
        public static void Main()
        {
            string[] parts = Console.ReadLine().Split(' ');
            long a = long.Parse(parts[0]);
            long b = long.Parse(parts[1]);
            Console.WriteLine(a + b);
        }
    }
  • Count words with a Dictionary

    using System;
    using System.Collections.Generic;
    
    public class Program
    {
        public static void Main()
        {
            var count = new Dictionary<string, int>();
            foreach (var word in "to be or not to be".Split(' '))
            {
                count[word] = count.ContainsKey(word) ? count[word] + 1 : 1;
            }
            foreach (var pair in count)
            {
                Console.WriteLine(pair.Key + ": " + pair.Value);
            }
        }
    }
  • 30 factorial with BigInteger

    using System;
    using System.Numerics;
    
    public class Program
    {
        public static void Main()
        {
            BigInteger f = 1;
            for (int i = 2; i <= 30; i++) f *= i;
            Console.WriteLine(f);
        }
    }