3 ms·
$CSharpCode = @" using System; public class HelloWorld { public static void SayHello() { Console.WriteLine("Hello,
by p_ing 2y 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# ;-)
- lIl-IIIl 2y agoEven better, C# has top-level methods, no classes needed: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...
- p_ing 2y agoDoes that run under Windows PowerShell, or just PowerShell [core]?