p_ing 6 days ago

    $CSharpCode = @"
    using System;
    
    public class HelloWorld
    {
        public static void SayHello()
        {
            Console.WriteLine("Hello, World!");
        }
    }
    "@

    Add-Type -TypeDefinition $CSharpCode -Language CSharp
    [HelloWorld]::SayHello()
There's your scriptable-in-PowerShell C# ;-)

1
lIl-IIIl 5 days ago

Even better, C# has top-level methods, no classes needed:

https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...

p_ing 5 days ago

Does that run under Windows PowerShell, or just PowerShell [core]?