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不一定需要存在于作用域中。