Advertisement

Public

What does Public mean?

Public, in C#, is a keyword used to declare the accessibility of a type and type member such that the access is not limited. It is one of the access modifiers that provides complete visibility to all types and type members.

C# encourages the use of information hiding, which is the fundamental principle of object-oriented language that helps to improve software quality. Hence, a member of a type has private accessibility by default. This only has to be modified when that member has to be accessible by any code in the assembly in which it is declared or another assembly that references the member.

Some of the C# constructs like namespace, members of an interface and members of an enumeration have public accessibility and do not allow any other accessibility. In addition, user-defined types that overload specific operators for providing custom implementation have to declare the overloaded operators as public.
Advertisement

Techopedia explains Public

Public is the most permissive accessibility out of all the other accessibilities, which include private, protected and internal accessibility. This is because there is no restriction on accessing a public type or type member - it can be used for both instance and static members of a type.

For example, BankAccount class represents the account details of a user and can have a public method, DisplayAccountBalance, so that any other class within the assembly or the assembly referencing the class can call this method to display the balance.

In contrast to C++, public members of a base class can only be public in all their derived classes. In C#, there is no option to specify access modifiers, whether protected or private, during derivation of a class.

While public accessibility is used to access a type or its member from a code in the same assembly or another assembly that references it, internal accessibility can be used to access types from within the assembly.
Advertisement

Share this Term

  • Facebook
  • LinkedIn
  • Twitter

Survey: Why Is There Still a Gender Gap in Tech?

Do you work in the tech industry? Help us learn more about why the gender gap still exists in tech by taking this quick survey! Survey respondents will also be entered to win a $100 Amazon Gift Card!

Related Reading

Tags

Development.NETProgramming LanguagesC Sharp

Trending Articles

Newest Articles

Go back to top