Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Why do you need to put both of these in an ASP.NET page:

 

<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Data" %>

 

Doesn't the <%@ import Namespace="System.Data" %> statement also include objects in System.Data.SqlClient?

  • Administrators
Posted
You are required to import the namespaces explicitly, this prevents confusion when the same classname occurs in multiple sub namespaces and compilation errors if in future a revised library version may introduce a duplicate classname in a sub namespace.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

So, if there is a class Person in System.People.Person, and a class Person in MyLib.People.Person, then I can do this:

<%@ import Namespace="MyLib.People.Person" %>
<%@ import Namespace="System.People" %>

... and I will be sure, when instantiating class Person, to get Person from Mylib.People and not System.People? .NET will know that MyLib.People.Person is the most explicit so it will use that?

  • Administrators
Posted

You can't import down to the class level, only the namespace so the 1st line would be invalid. If you have duplicate definitions you could alias a namespace to a shorter version and use that to fully qualify classnames

 

<%@ import Namespace="MyPeople = MyLib.People" %>
<%@ import Namespace="System.People" %>

'you could now use
MyPeople.Person
'and can always use
MyLib.People.Person

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...