Search code examples
c#staticinstanceinternalsaccess-specifier

Why is an internal static string is not accessible from outside the class?


I have a class defined as follows:

class Foo
    {
        internal string IString;
        internal static string IstaticString;
        public Foo()
        {
            IstaticString = "static";
            IString = "non - static";
        }
    }

I am creating its instance in the main function as the following, in this caseIString is accessible through the object, whereas IstaticString is not accessible. Can anyone explain the reason for this?

enter image description here


Solution

  • Static fields accessible from type not from instance. This Foo.IstaticString should work