Is there a programmatic benefit to using a using statement?
Notice the difference between this sample:
using Application.Data;
namespace Application.Web
{
public class SampleClass
{
public void SampleMethod()
{
List<Category> categories = CreateCategoriesData();
Category expected = categories[0];
...
...
}
}
}
And this one:
namespace Application.Web
{
public class SampleClass
{
public void SampleMethod()
{
List<Data.Category> categories = CreateCategoriesData();
Data.Category expected = categories[0];
...
...
}
}
}
There is no “programmatic” benefit: once the code is compiled, there is no difference in the generated libraries or executables. It is a matter of preference and sometimes coding standards of your organization. Our company prefers using the
usingexcept for rare cases where it is not possible.