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 o开发者_如何学Pythonnly option http://blogs.msdn.com/b/ericgu/archive/2004/08/05/209267.aspx
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
local-variable-declaration:
local-variable-type local-variable-declarators
To support different local variable types you need to use some form of nesting. For example
using (Type1 local1 = new Type1(), local2 = new Type1())
using (Type2 local3 = new Type2(), local4 = new Type2())
{
}
No. It is similar to the following:
int a, b;
Both a and b are int - that is it.
精彩评论