-1

I have created a .cs files that contain the following:

namespace SetUp
{
    class Config
    {
        public static object SetConfig(int code, bool print)
        {
           //My Code
        }
    }
}

Compiled it and added the reference to my main project called 'CSharp Side', for example. Added it to my project and everything is great. But my question is how do I access 'SetConfig()'? Because it doesn't recognize 'SetUp' or 'Config' in my code.

roydbt
  • 91
  • 1
  • 8

2 Answers2

3

Simply make your class as public.

namespace SetUp
{
  public class Config
  {
    public static object SetConfig(int code, bool print)
    {
      //My Code
    }
  }
}
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
Ehsan Ullah Nazir
  • 1,827
  • 1
  • 14
  • 20
-1

You can reference code in a different assembly by fully qualifying:

SetUp.Config.SetConfig(1, true);

or include the namespace with a using directive:

using SetUp;

class SomeClass
{
    void SomeMethod()
    {
        Config.SetConfig(1, true);
    }
}

Also, both the class and the method in the referenced assembly need the public modifier. Otherwise they won't be visible outside the assembly where they are defined.

Cee McSharpface
  • 8,493
  • 3
  • 36
  • 77
  • 1
    It says: 'Config' is inaccessible due to its protection level – roydbt Jan 13 '18 at 18:20
  • 1
    this has been covered in depth, for example [here](https://stackoverflow.com/a/614844/1132334) and [here](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers) – Cee McSharpface Jan 13 '18 at 18:21