C# 将IronPython变量设置为None

C# 将IronPython变量设置为None,c#,ironpython,C#,Ironpython,如何使用ScriptScope.SetVariable将IronPython作用域内的变量值从C#设置为无,而不使用ScriptEngine.executeAndRap(“x=None”,scope)?是否需要在ScriptEngine/ScriptScope中定义变量?这个例子不起作用: // Note: "scope" is the ScriptScope variable assigned beforehand scope.SetVariable("x", null); web搜索找到

如何使用
ScriptScope.SetVariable
将IronPython作用域内的变量值从C#设置为无,而不使用
ScriptEngine.executeAndRap(“x=None”,scope)
?是否需要在ScriptEngine/ScriptScope中定义变量?这个例子不起作用:

// Note: "scope" is the ScriptScope variable assigned beforehand

scope.SetVariable("x", null);
web搜索找到了此相关链接,但未提供解决方案:

据我所知,关键字
object
只是
System.object
的别名,但我发现将
null
强制转换为
System.object
在某些情况下有效

scope.SetVariable("x", (Object)null);

谢谢!我确实发现,在调用SetVariable之前,var不一定需要存在于作用域中。像Charm一样工作在调用SetVariable之前,var不一定需要存在于作用域中。