Quick actions

cmd+k|ctrl+k

Navigation

Languages

Protected members

Snippet info

Language

Csharp

Visibility

public

Author

dhaval-90

Created

2022-01-30T19:03:21.877291Z

Updated

2022-05-03T09:11:16.31927Z

using System;
using System.Collections.Generic;
using System.Linq;

public class A
{
    protected int x = 123;
}

public class B : A
{
    
}

class Program 
{
    static void Main()
    {
        var a = new A();
        var b = new B();

        // Error CS1540, because x can only be accessed by
        // classes derived from A.
        // a.x = 10;

        // OK, because this class derives from A.
        //b.x = 10;
        //Console.WriteLine(b.x);
        Console.WriteLine("Hello");
    }
}
INFO