Referencing another source file

  • Thread starter Thread starter PLS
  • Start date Start date
P

PLS

I guess I'm a bit confused about how to organize a C# project.

I have two .cs files compiling into one assembly. Both place classes
into the same namespace.

File A contains a class with a bunch of static methods that I want to
use in file B.

What do I put into B to make the class and methods visible?

Thanks,
++PLS
 
PLS,

If the classes are in the same namespace, in the same assembly, you
should be able to make the call by using the class name, followed by the
static method/property/field you wish to access. Basically, like any other
static class. For example:

In File 1:

public static class StaticClass
{
public static void DoSomething()
{
}
}

In File 2:

public class OtherClass
{
// Make the call.
public void DoSomethingElse()
{
// Call the static method on StaticClass.
StaticClass.DoSomething();
}
}
 
PLS said:
I guess I'm a bit confused about how to organize a C# project.

I have two .cs files compiling into one assembly. Both place classes
into the same namespace.

File A contains a class with a bunch of static methods that I want to
use in file B.

What do I put into B to make the class and methods visible?

Odds are, you're just missing the keyword "Public".

Put it on your class definitions:

Public class MyClass
{
}

And on the methods you want in the class to be visible.
 
I doubt that is it. If they are in the same assembly, then a missing
access modifier on the class will default to internal, which would make it
accessible to the other class in the same assembly.
 
Back
Top