Hi Andy,
The main problem of the user is really to do with the namespace.
In Company1.Company2, the Company2 namespace is shielded, so if you want to
do like this:
using System;
namespace Company2
{
public class SomeFunctions
{
public void FunctionA()
{
// Do Something.
Console.WriteLine("Company2.SomeFunctions.FunctionA()");
}
}
}
namespace Company1.Company2
{
public class SomeFunctions
{
public void FunctionB()
{
Company2.SomeFunctions c2=new Company2.SomeFunctions();
c2.FunctionA();
}
}
}
The compiler will generate an error denotes
"'Company1.Company2.SomeFunctions' does not contain a definition for
'FunctionA'".
So you should use "using" alias, like this:
using System;
using x=Company2;
namespace Company2
{
public class SomeFunctions
{
public void FunctionA()
{
// Do Something.
Console.WriteLine("Company2.SomeFunctions.FunctionA()");
}
}
}
namespace Company1.Company2
{
public class SomeFunctions
{
public void FunctionB()
{
x.SomeFunctions c2=new x.SomeFunctions();
c2.FunctionA();
}
}
}
Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| From: (e-mail address removed) (Andy Renk)
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Subject: Re: Accessing another namespace
| Date: 21 Oct 2003 17:46:53 -0700
| Organization:
http://groups.google.com
| Lines: 66
| Message-ID: <
[email protected]>
| References: <#
[email protected]>
<
[email protected]>
| NNTP-Posting-Host: 131.107.3.86
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1066783614 5617 127.0.0.1 (22 Oct 2003
00:46:54 GMT)
| X-Complaints-To: (e-mail address removed)
| NNTP-Posting-Date: Wed, 22 Oct 2003 00:46:54 +0000 (UTC)
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!postnews1.google.com!no
t-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:193046
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| The problem I see does not have to do with the namespace, but with the
| fact that
| you are trying to call a function (FunctionA()
![Wink ;) ;)](/styles/default/custom/smilies/wink.gif)
that is not static.
| To call this function you first have to make an instance of a class
| (Company2.SomeFunctions test = new Company2.SomeFunctions(); )
| then use that object to call the variable
| (test.FunctionA()
![Wink ;) ;)](/styles/default/custom/smilies/wink.gif)
| If you want the function to be called without it requiring to be in a
| class, make it static using the "static " key word in front of the
| function.
|
| The below code should help you out with this
|
| Best of luck
|
| Andy Renk junker_mail(Remove)@yahoo.com -- to email delete the
| "(remove)"
|
| Samle COde
| ********************
| using System;
| namespace a
| {
| class SomeFunctions
| {
|
| [STAThread]
| static void Main(string[] args)
| {
| Function(); // calls function in
| namespace a
| b.SomeFunctions.Function(); // calls function in
| namespace b
| c.SomeFunctions tempClass = new c.SomeFunctions(); // make
| class
| //from
| namespace c
| tempClass.Function(); // ececute call from class in
| namespace c
| }
| public static void Function()
| {
| Console.WriteLine("This is the Function is namespace a");
| }
| }
| }
| namespace b
| {
| class SomeFunctions
| {
| static public void Function()
| {
| Console.WriteLine("This is the Function is namespace b");
| }
| }
| }
| namespace c
| {
| class SomeFunctions
| {
| public void Function()
| {
| Console.WriteLine("This is the Function is namespace c");
| }
| }
| }
|