It is not possible to have variables of different declared types in the same using statement. The C # specification limits the set of valid constructs to a single expression or local variable declaration. The latter is described in section 8.5.1 of the C # lang specification and provides only one type of variable
local-variable-declaration: local-variable-type local-variable-declarators
To support different local types of variables, you need to use some form of nesting. for instance
using (Type1 local1 = new Type1(), local2 = new Type1()) using (Type2 local3 = new Type2(), local4 = new Type2()) { }
source share