Answers for "private protected c#"

C#
1

private protected c#

// The private protected keyword combination is a member access modifier. 
// A private protected member is accessible by types derived from the containing class, 
// but only within its containing assembly. 

public class BaseClass
{
    private protected int myValue = 0;
}

public class DerivedClass1 : BaseClass
{
    void Access()
    {
        var baseObject = new BaseClass();

        // Error CS1540, because myValue can only be accessed by
        // classes derived from BaseClass.
        // baseObject.myValue = 5;

        // OK, accessed through the current derived class instance
        myValue = 5;
    }
}
Posted by: Guest on October-17-2021

Code answers related to "private protected c#"

C# Answers by Framework

Browse Popular Code Answers by Language