What is assembly in C?#

I have defined the access modifier private protected, it is written that it will be available in this build, but what is meant by the word "build"?

Author: ion, 2020-09-10

1 answers

If global, then the assembly is a structural unit in .NET . It can be in the form of exe or dll files. I.e., for example, yours .The NET Framework Class Library will be an assembly after the build. About the access modifier. Consider both parts of this composite access modifier:

  1. private is a private class or class member. There is no external access to it. That is, if the method has the private modifier, then it can only be used within the class in which it is defined.
  2. protected - such a class member is only available within the class and in the heirs of this class. Note that the inheritors can be located in other assemblies as well.

private protected - such a class member is available inside this class, as well as in classes that are inheritors of this class and are in the same assembly with it.

More clearly.

ClassLibrary-Third-party library (single build)
ConsoleApp1-Console application (other assembly)

namespace ClassLibrary
{
    public class Helper
    {
        private protected void Convert()
        {
            // logic
        }
    }
}

namespace ClassLibrary
{
    public class JsonHelper : Helper
    {
        public void Test()
        {
            //доступ есть
            Convert();
        }
    }
}
 
namespace ConsoleApp1
{
    public class XmlHelper : Helper
    {
        public void Test()
        {
            // доступа нет
            Convert();
        }
    }
}

That is, as we can see, Helper. Convert will be available inside Helper and inside JsonHelper. Since JsonHelper is the heir and is defined in the same assembly.

Inside XmlHelper, the Helper.Convert method will no longer be available. Although XmlHelper is the successor of Helper, but it is in a different build.

 3
Author: Sterlukin, 2020-09-10 18:36:20