-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
  • 35
  • 1
  • 7

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
  • 60,736
  • 15
  • 100
  • 154
Ehsan Ullah Nazir
  • 1,607
  • 1
  • 11
  • 19
-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
  • 7,960
  • 3
  • 31
  • 70
  • 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://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers) – Cee McSharpface Jan 13 '18 at 18:21