Reference .cs File From .cs File

D

David

I have two classes and a web page: test1.cs, test2.cs, and test.aspx.
I know how to add a reference to test1.cs from test.aspx using the
assembly directive (<%@ Assembly Src="test1.cs" %>). This works fine,
but what if test1.cs needs to call a method from test2.cs. How can I
add a reference to test2.cs from test1.cs without compiling either?

--------test.aspx--------
<%@ Page Language="C#"%>
<%@ Assembly Src="test1.cs" %>
<%@ Assembly Src="test2.cs" %>

<script runat="server">
void Page_Load() {
Response.Write(ns1.ClassOne.SomeMethod());
Response.Write("<br>");
Response.Write(ns2.ClassTwo.AnotherMethod());
}
</script>


--------test1.cs--------
namespace ns1 {
public class ClassOne {
public static string SomeMethod() {
return "return from SomeMethod class one";
//How do I call AnotherMethod() from here???
}
}
}


--------test2.cs--------
namespace ns2 {
public class ClassTwo {
public static string AnotherMethod() {
return "return from AnotherMethod class two";
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top