I am little bit confused.
I know that public is accessible from anywhere and internal classes are accessible only within the assembly.
But I found something strange in my code.
I've got three projects in one solution. All projects shares the same namespace.
Project A (main executable)
namespace Everything
{
class Program
{
void Main()
{
Runner r = new();
}
}
}
Project B (library class)
namespace Everything
{
public class Runner
{
public Runner()
{
// Loads external assembly in runtime and creates instance
Assembly assembly = Assembly.Load("my.dll","my.pdb");
Type type = assembly.GetType("Everything.InternalClass");
Execute Instance = (Execute)Activator.CreateInstance(type);
}
}
public class Execute
{
//something to do
}
}
And finally Project C (my.dll) (another class library)
namespace Everything
{
class InternalClass : Execute
{
// This is executed in correct way - even it is in different assembly and it is set as internal (by default)
}
}
Why this is working properly? I was thinking, that I need to use public in my Project C - becuase it is in different assembly...