rider

JetBrains Rider - how to execute a C# scratch


In JetBrains Rider, when I create a scratch C# file, how can I execute it? Making the Main method public static and adding a namespace seems to be not enough.

Unable to find static method: MyNamespace.Foo.Main

using System;

namespace MyNamespace
{
    public class Foo
    {
        public static void Main()
        {
            Console.WriteLine("hello");
        }
    }
}

Rider version: JetBrains Rider 2022.3.1

Windows 10


Solution

  • Adding a namespace is actually not even required. What worked for me is the following:

    using System;
    
    class Foo
    {
        public void Main()
        {
            Console.WriteLine("hello");
        }
    }
    

    You can also find a good description on this page: https://blog.jetbrains.com/dotnet/2017/12/01/c-interactive-rider/

    I hope this helped!