假设我有:
using(DbDataReader reader = getReader("SELECT * FROM Cmds", out DbCommand cmd))
{
}
我编写了一个辅助方法,名为getReader
,用于获得DbDataReader
和DbCommand
。在这种情况下,using
语句是否调用输出参数cmd
的Dispose
方法?如果不是,有没有更简洁的方法来实现这一点,而不是使用类似以下的代码:
DbCommand cmd = null;
try
{
using(DbDataReader reader = getReader("select value from cmds where typeid = 2;", out cmd))
{
}
}
finally
{
cmd?.Dispose();
}
我可以返回一个包含两个可丢弃对象的元组吗?还是这会让using
语句混淆?
我查看了C#中using
语句的MSDN文档,但它没有提及在表达式中使用out
参数。