I thought that assembly is a project in a solution in Visual Studio, but then I was trying to understand inheritance and internal/protected access modifiers and I got lost.
*Project1
and Project2
are separate VS projects in one solution:
namespace Project1
{
public class C1
{
internal int field1;
internal protected int field2;
}
}
namespace Project2
{
public class C2
{
public static void f(C1 c1)
{
c1.field1 = 1; //no problems here
c1.field2 = 2; //neither here
}
}
}
In Project2
I have no inheritance so both fields field1
and field2
should be inaccessible but there's no errors at all. (I added Project1 into Project2 References and add using Project1
in Project2
)
Your solution works, because it contains errors that Visual Studio can ignore.
You have a fully functional project Project1, containing a
Main()
. This is the project that is set as startup project, which can run because it contains no errors.Not all project in your solution have to successfully build in order for one project to run; just the projects that the project you want to run depends on. In this case none.
Right-click Project2, click "Set as StartUp Project" and try to build or run it: you'll see the compiler errors you're expecting.