Skip to content

Demonstrates how different access modifiers control the accessibility of fields and methods within a class.

Notifications You must be signed in to change notification settings

jepozdemir/csharp_access_modifiers

Repository files navigation

C# Access Modifiers

This repository contains code samples referenced in my Medium blog post, "C# Access Modifiers". This post and repository focus on understanding and utilizing access modifiers in C#, which control the visibility of classes, methods, and other members.

Overview

In this blog post, I discuss various access modifiers in C# that help define the scope and accessibility of types and their members. Each modifier is demonstrated with code examples to show how they can be effectively used to implement encapsulation and data hiding.

Accessibility Levels Covered

  • Public
    Members are accessible from anywhere.

  • Private
    Members are accessible only within the containing class.

  • Protected
    Members are accessible within the containing class and by derived class instances.

  • Internal
    Members are accessible only within the same assembly (project).

  • Protected Internal
    Members are accessible from within the same assembly or from derived classes in another assembly.

  • Private Protected
    Members are accessible within the containing class and by derived class instances, but only if those derived classes are within the same assembly.

  • File (Internal)
    Members are accessible only within the file in which they are declared.

How to Use

  1. Read the Blog Post: Start by reading the full blog post on Medium here.
  2. Explore Code Samples: Review the repository for code examples demonstrating each access modifier.
  3. Practice Usage: Use the provided examples to practice applying access modifiers in your own C# projects.

Contributing

Contributions are welcome! If you have suggestions for improvements or additional examples, feel free to open an issue or submit a pull request.

Feedback and Suggestions

If you have any feedback on the blog post or this repository, please leave a comment on the Medium post or reach out through GitHub issues.

License

This project is licensed under the MIT License.

Thank you! If you found this helpful and would like to show support; don't forget to give it a star and share it with others who might benefit from it.👏👏👏👏👏

Releases

No releases published

Packages

No packages published

Languages