What is Public Access Modifier in C#?You can associate
public access modifier to a type or any members of the type.
Members with access modifier as public can be accessed by any class belonging to any project. This modifier provides the higher level of visibility. Consider the following example: public class
sampleClass { Output of this code will be: obj.member1=10 In this example,
you have created two classes namely sampleClass and testClass. You have
associated public modifier with these classes. You have also marked their
members as public. Since member1 is a public member of sampleClass, it
can be directly accessed from any class using an instance of sampleClass.
This is demonstrated inside Main method of testClass, where in you create
an instance of sampleClass and you perform read and write operations on
member1 directly.
|