This is more a feature than an issue. It would be nice if we can use "using" block with multiple resources such as below:
using(var custSvc = new CustomerService(), var empSvc = new EmployeeService()) { }
I do not for see any limitations to being able to achieve this but I could be wrong.
This is a duplicate of https://github.com/dotnet/roslyn/issues/2331 (only with , instead of ;), which was closed as "Won't fix" by @gafter:
The benefit of this proposal seems close to zero, plus or minus epsilon.
The benefit is readability. It prevents nested usings or declaring one resurce in a using and the other not which makes it inconsistent.
You don't need to nest usings in blocks:
c#
using (var custSvc = new CustomerService())
using (var empSvc = new EmployeeService())
{
}
That's good enough then, at least in the surface. I wonder if ugly nested 'try.. catch.. finally..' get created in the background but that's a different issue.
VB version also generates two try block.
using custSvc = new CustomerService(), empSvc = new EmployeeService()
end using
Not sure if it incurs any performance penalties, though.
Dup of #2331
Most helpful comment
You don't need to nest
usings in blocks:c# using (var custSvc = new CustomerService()) using (var empSvc = new EmployeeService()) { }