September 19, 2008

C# - Access specifier for methods


If you wirte a function in a class and dont specify any access specifier for that class, then the default access for that function is Private. Which implies that it is not accessible to any class(either child class or not) within that namespace or outside that namespace.

If you want everyone to access that function give it public access. If you want only child classes to access that function give it protected access.

Note:If you gave public access for that function and there default access for the containing class then you will not have access for that public function outside the namespace. This is because you have opened the room door(function is public) but u haven't opened the main door(class not public) for pupil outside the namespace

0 comments: