Private Access Specifiers (C#)

private-specifiers
In this chapter you will learn:

  • What is Private Access Specifier?
  • What is the boundary of private access specifier in C#?
  • How to use private access specifier in C# programming?

The private access specifiers restrict the member variable or function to be called outside from the parent class. A private function or variable cannot be called outside from the same class. It hides its member variable and method from other class and methods. However, you can store or retrieve value from private access modifiers using get set property. You will learn more about get set property in lateral chapter.

  • Example:

    Output

    Error 1: Private_Access_Specifiers.access.name’ is inaccessible due to its protection level __

    private access-specifiers

    In the above example, you cannot call name variable outside the class because it is declared as private.

    Summary

    In this chapter you learned what is the private access specifier in C#? You also learned its scope and boundary and implementation in programming. In next chapter you will learn Protected Access Specifier in C#.


    One thought on “Private Access Specifiers (C#)”

    Leave a Reply

    Your email address will not be published. Required fields are marked *