ironpython - IronPython中的C#“using” block 等效于什么?

标签 ironpython idisposable

IronPython中的等效功能是什么?它只是最后的尝试块吗?

using (var something = new ClassThatImplementsIDisposable())
{
  // stuff happens here
}

最佳答案

IronPython支持将IDisposablewith语句一起使用,因此您可以编写如下内容:

with ClassThatImplementsIDisposable() as something:
    pass

关于ironpython - IronPython中的C#“using” block 等效于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1757296/

相关文章:

C# - "destructors are not inherited"实际上是什么意思?

c# - 在 ASP.NET 中实现文件下载时如何处理我的文件流?

c# - 如何处理 ManualResetEvent

c# - 在 c# 中创建一个 IDisposable 类,它在完成时清理一个 SqlConnection

python - 用于 Python/IronPython 的 Eclipse 中的 GUI 运行器

python - 为什么Python(IronPython)在使用bin这个词时会报 "Illegal characters in path"?

python - 如何使用 CPython 让泛型在 Python.NET 中工作

.net - IDisposable 对象是否意味着只创建和处理一次?

exception - 在 C# 中捕获 Ironpython 异常

c# - IronPython 覆盖 __setattr__ 和 __getattr__