Groups | Blog | Home
all groups > asp.net > january 2008 >

asp.net : Importing namespaces in a class


bruce barker
1/23/2008 12:35:04 PM
using System.Collections.Specialized;

-- bruce (sqlwork.com)


[quoted text, click to view]
Peter Bromberg [C# MVP]
1/23/2008 12:53:00 PM
MyClass should have a reference to MyOtherClass, and a using statement at the
top of its class file in order to use a namespace defined in MyOtherClass.cs
.. You don't need it at the @Page level at all.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com


[quoted text, click to view]
David Wier
1/23/2008 2:13:44 PM
It's just the basic:
Imports System.Collections.Specialized

And yes, import it only in the class - it will automatically get referenced
in the page, when you instantiate the class.

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup


[quoted text, click to view]

David Wier
1/23/2008 4:20:46 PM
Put that at the very top of the page, before the Class declaration

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup


[quoted text, click to view]

Ralph Wiggum
1/23/2008 8:48:57 PM
I have an aspx that looks like this:

<%@ Import Namespace="System.Collections.Specialized" %>
<%@ Assembly Src="MyClass.cs" %>
....

Ralph Wiggum
1/23/2008 9:43:00 PM
Ok, thanks. But what if the namespace is defined in a separate file, MyOtherClass.cs and I need to use it in MyClass.cs:

<%@ Import Namespace="NamespaceInMyOtherClass" %>
<%@ Assembly Src="MyClass.cs" %>
<%@ Assembly Src="MyOtherClass.cs" %>
....

How can I tell MyClass.cs to import from MyOtherClass.cs when I remove the first line above?


[quoted text, click to view]
Ralph Wiggum
1/23/2008 10:23:01 PM
I'm pretty sure the compiler will complain about "using NamespaceInMyOtherClass;" in the code below. How can I tell MyClass to look in the MyOtherClass.cs file?

aspx:
<%@ Assembly Src="MyClass.cs" %>
<%@ Import Namespace="MyClass" %>
<%
MyClass mc = new MyClass();
%>

MyClass.cs:
namespace MyClass{
public class MyClass{
using NamespaceInMyOtherClass; <-- Problem!
public MyClass(){
MyOtherClass moc = new MyOtherClass();
}
}
}

MyOtherClass.cs:
namespace NamespaceInMyOtherClass{
public class MyOtherClass{

}
}



[quoted text, click to view]
Ralph Wiggum
1/23/2008 11:48:10 PM
I'm probably a little slow, but "that" is...?

[quoted text, click to view]
AddThis Social Bookmark Button