In the following example, two classes are declared, Point and MainClass. The public members x and y of Point are accessed directly from MainClass.
class PointTest
{
public int x;
public int y;
}
class MainClass4
{
static void Main()
{
PointTest p = new PointTest();
// Direct access to public members:
p.x = 10;
p.y = 15;
Console.WriteLine("x = {0}, y = {1}", p.x, p.y);
}
}
// Output: x = 10, y = 15
If you change the public access level to private or protected, you will get the error message:
'Point.y' is inaccessible due to its protection level.