0

If a Visual Studio 2010 solution contains two C# projects where the second projects references the first project:

If a public static variable is declared in a class in the first project, should it be visible to a class in the second project?

1
  • agreed, this seems like a valid question. Commented Mar 18, 2014 at 4:42

2 Answers 2

3

Yes, and no. It all depends on the access modifier

First off, the second project has to have a reference to the first.

Second, the owning object has to be marked public and not internal.

Finally, the field/variable itself has be marked as public and not internal/private/protected

2
  • Yes, many times. If you post some code we might be able to assist further. Commented Mar 18, 2014 at 4:54
  • and just to add another twist, project A can have its internals visible to project B, in which case, public or internal work. Commented Mar 18, 2014 at 5:36
1

It will be visible if you make it public. By default it's private.

Of course, you need a reference to the other project.

Cheers

EDIT: It goes without saying that the class itself must be public.

public class Class1
{
    public static string zaza = "zaza";
}
1
  • Yes, why ? Are you still having issues with it ?
    – Luc Morin
    Commented Mar 18, 2014 at 4:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.