Sobes.tech
Junior — Middle

Is it possible to define a function with protected access level inside a class method?

sobes.tech AI

Answer from AI

In C#, you cannot define a function with the protected access level inside a class method. Access modifiers (public, private, protected, internal) are declared at the class level, not inside other methods. Nested functions (local functions) inside a method cannot have access modifiers — they are always accessible only within that method.

Example of a local function inside a method:

class MyClass
{
    protected void OuterMethod()
    {
        void InnerFunction()  // local function, without access modifier
        {
            // code
        }

        InnerFunction();
    }
}