
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- What are access modifiers and non-access modifiers in Java?
- Access Modifiers in C++
- Access Modifiers in Java
- Access and Non Access Modifiers in Java
- What are the differences between access modifiers and non-access modifiers in Java?
- What are access modifiers in C++?
- Types of access modifiers in Java?
- Non Access Modifiers in Java\n
- method overriding with access modifiers in Java
- java access modifiers with method overriding
- How many non-access modifiers are there in Java?
- What are final, abstract, synchronized non-access modifiers in Java?
- Can access modifiers be used for local variables in Java?
- What are different types of access modifiers available in C#?
- Why cannot we specify access modifiers inside an interface in C#?

Advertisements