As it says, Which section of a class should be public?
I really feel like this is a security question myself.
“What class components are typically designated as public?”
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
C# access modifiers are an aspect of design and cannot really be used for security. Obviously they can help you implement some kind of security by enforcing (really just encouraging) certain access patterns (i.e. your internal APIs encourage database connections only through some kind of factory which connects with a connection string created securely or in some consistent way, or all access to passwords is through classes which are designed to properly scramble the memory and encrypt on disk), but they can’t really enforce security.
Public, private, protected and internal are the access modifiers applied to classes and members and relate to the interfaces exposed and how they behave with respect to inheritance, intra and inter-assembly-level access.
What should be public are members which need access visibility outside the class (and outside the assembly). Anything else should not be exposed until its need for visibility in the interface is properly justified. In many cases, I would suggest most things be private until justified that they need to be public. Sometimes they are immediately obvious. Certainly for static members you should really be careful about exposing as public.