跳转到内容

C# 代码

C# 通过编译为 WebAssembly 的 .NET 运行,使用 Roslyn 脚本引擎。运行时已内嵌在 Restorm 中:您的机器上无需安装任何 .NET SDK。

符号作用
input从输入端口收到的值
vars运行变量的一个字典
Console.Write / Console.WriteLine写入执行日志
最后的表达式它的值会从 result 端口发出

代码是 C# 脚本(Roslyn 风格):无需编写外层类,也无需 Main,语句直接写在顶层, 最后的表达式即为结果。

using System.Linq;
using System.Text.Json;
var doc = JsonDocument.Parse(input.ToString());
var commandes = doc.RootElement.GetProperty("commandes").EnumerateArray();
var payees = commandes
.Where(c => c.GetProperty("statut").GetString() == "payee")
.ToList();
var total = payees.Sum(c => c.GetProperty("montant").GetDouble());
Console.WriteLine($"{payees.Count} commandes payées, total {total}");
new { nombre = payees.Count, total }

.NET 的基础类库System.LinqSystem.Text.JsonSystem.Text.RegularExpressionsSystem.Security.CryptographySystem.Collections.Generic……

当您想复用已经用 C# 写好的业务逻辑,或者您的团队更熟悉它时,就选这门语言 —— 而不是在您需要调用什么东西的时候选它。