|
This post originated from an RSS feed registered with .NET Buzz
by Eric Gunnerson.
|
Original Post: Why does "using" only import types, not namespaces?
Feed Title: Eric Gunnerson's C# Compendium
Feed URL: /msdnerror.htm?aspxerrorpath=/ericgu/Rss.aspx
Feed Description: Eric comments on C#, programming and dotnet in general, and the aerodynamic characteristics of the red-nosed flying squirrel of the Lesser Antilles
|
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Eric Gunnerson
Latest Posts From Eric Gunnerson's C# Compendium
|
|
Given a type named:
System.Data.SqlClient.SqlConnection
The following works:
using System.Data.SqlClient;
...
SqlConnection connection;
But this is an error:
using System.Data;
...
SqlClient.SqlConnection connection;
Why?
Well, the rule is that C# only imports the types in the namespace mentioned in the "using" statement.
Back in the early days of C#, we had a slightly different rule, which I *think* also imported namespaces as well as types, but with that behavior, users were getting into situations where they had name collisions and were having difficulty figuring out what was going on (and, perhaps, coming up with workarounds - we obviously didn't have the global namespace operator coming in Whidbey), so we decided to limit the number of things that go into the global namespace.
Read: Why does "using" only import types, not namespaces?