HardCode Posted August 16, 2004 Posted August 16, 2004 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? Quote
Administrators PlausiblyDamp Posted August 16, 2004 Administrators Posted August 16, 2004 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
HardCode Posted August 16, 2004 Author Posted August 16, 2004 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? Quote
Administrators PlausiblyDamp Posted August 16, 2004 Administrators Posted August 16, 2004 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 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.