Home >Backend Development >C#.Net Tutorial >Access modifiers in C#
Access modifiers specify the scope of variables and functions in C#. The following are the access modifiers provided by C#:
The public modifier places no restrictions on member access.
Access is limited to derived classes or class definitions.
Internal access modifiers within a program with the following permissions access its declaration.
It has access specifiers provided by both protected and internal access modifiers.
Restricted to the class in which it is declared. Members designated as private cannot be accessed outside the class.
Let us see an example of protected access modifier, accessing protected members -
Live Demonstration
using System; namespace MySpecifiers { class Demo { protected string name = "Website"; protected void Display(string str) { Console.WriteLine("Tabs: " + str); } } class Test : Demo { static void Main(string[] args) { Test t = new Test(); Console.WriteLine("Details: " + t.name); t.Display("Product"); t.Display("Services"); t.Display("Tools"); t.Display("Plugins"); } } }
Details: Website Tabs: Product Tabs: Services Tabs: Tools Tabs: Plugins
The above is the detailed content of Access modifiers in C#. For more information, please follow other related articles on the PHP Chinese website!