![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Access Modifiers in C#
Access Modifiers specifies the scope of variable and functions in C#. The following are the access modifiers used provided by C#:
Public
The public modifier sets no restriction on the access of members.
Protected
Access limited to the derived class or class definition.
Internal
The Internal access modifier access within the program that has its declaration.
Protected internal
It has both the access specifiers provided by protected and internal access modifiers.
Private
Limited only inside the class in which it is declared. The members specified as private cannot be accessed outside the class.
Example
Let us see an example of protected access modifier, accessing the protected members −
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"); } } }
Output
Details: Website Tabs: Product Tabs: Services Tabs: Tools Tabs: Plugins
Advertisements