嵌套使用块
我知道我们可以在 using 块中创建多个相同类型的实例!但是有没有一种方法可以让不同类型的实例嵌套或写入单个 using 块中?
我刚刚读到这篇文章,到目前为止这似乎是唯一的选择 http://blogs.msdn.com/b/ericgu/archive/2004/ 08/05/209267.aspx
I knew we could create more than one instance of the same type in a using block! but is there a way i could have different types instances nested or written in a single using block?
i just read this, so far it seems the only option
http://blogs.msdn.com/b/ericgu/archive/2004/08/05/209267.aspx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在同一个 using 语句中不可能有不同声明类型的变量。 C# 规范将有效构造集限制为单个表达式或局部变量声明。后者在 C# lang 规范的第 8.5.1 节中进行了介绍,并且仅提供单个变量类型
要支持不同的局部变量类型,您需要使用某种形式的嵌套。例如
It's not possible to have variables of different declared types in the same using statement. The C# spec limits the set of valid constructs to a single expression or a local variable declaration. The latter is covered in section 8.5.1 of the C# lang spec and only provides for a single variable type
To support different local variable types you need to use some form of nesting. For example
不,它类似于以下内容:
a 和 b 都是 int - 就是这样。
No. It is similar to the following:
Both a and b are int - that is it.