Skip to content

How Tos

Tareq Imbasher edited this page May 26, 2025 · 2 revisions

How to create a "Program-style" script?

The primary approach is to write Top-Level statements, ie:

var p = new Person
{
    Id = 1,
    Name = "John Doe"
};

p.Dump();

class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
}

To have a "Program" style script and a static Main() entry point, put it in a partial class Program:

partial class Program
{
    static void Main()
    {
        var p = new Person
        {
            Id = 1,
            Name = "John Doe"
        };

        p.Dump();
    }
}

class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
}

Another option without the class wrapper is:

void Main(string[] args)
{
    var p = new Person
    {
        Id = 1,
        Name = "John Doe"
    };

    p.Dump();
}

Main(args);

class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
}
Clone this wiki locally