The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Why does "using" only import types, not namespaces?

0 replies.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a flat view of this topic  Flat View
Previous Topic   Next Topic
Threaded View: This topic has 0 replies on 1 page
Eric Gunnerson

Posts: 1006
Nickname: ericgu
Registered: Aug, 2003

Eric Gunnerson is a program manager on the Visual C# team
Why does "using" only import types, not namespaces? Posted: Feb 1, 2005 9:11 PM
Reply to this message Reply

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?


Topic: The Infinite Cat Project Previous Topic   Next Topic Topic: Microsoft Releases Enterprise Library

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use