Access Modifiers in C#
In this post, you will learn how to work with access modifiers so that you can use that same knowledge and thus evolve.
- access modifiers are used to specify the declared accessibility of a variable (attribute), function (method), class, etc;
- there are five access modifiers (accessibility levels): public, protected, internal, protected internal and private;
- public ensures that access is not restricted to any part of our code;
- protected boils down to the possibility of access only within the class itself or within a class derived from it;
- the internal makes only if it is possible to have access inside the current namespace;
- protected internal means that you only have access to the current namespace and classes derived from another namespace;
- private means access only within the class itself.
using System;
namespace Base {
class AccessModifiers {
// public, protected, internal, protected internal and private
private void Run() {
Console.WriteLine("We are trying to learn how to work with the various access modifiers.");
}
}
}
Don’t forget to watch the video and you can always read this post in Portuguese.