[WEBINAR] Better to Ask Permission? Best Practices for Privacy and Security


Definition - 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.

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.
This definition was written in the context of C#
Share this:

Connect with us

Email Newsletter

Join thousands of others with our weekly newsletter

The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.