C#“使用"的等效项是什么?在IronPython中阻止? [英] What is the equivalent of the C# "using" block in IronPython?

查看:71
本文介绍了C#“使用"的等效项是什么?在IronPython中阻止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IronPython中的等效功能是什么?难道只是一个尝试最后的阻拦?

What's the equivalent of this in IronPython? Is it just a try-finally block?

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

推荐答案

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

IronPython supports using IDisposable with with statement, so you can write something like this:

with ClassThatImplementsIDisposable() as something:
    pass

这篇关于C#“使用"的等效项是什么?在IronPython中阻止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆