Lecture overview -- Keyboard shortcut: 'u'  Previous page: The current object - this -- Keyboard shortcut: 'p'  Next page: Creating and Deleting Objects [Section] -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 21 : 29
Object-oriented Programming in C#
Classes and Objects
Visibility Issues

A type has a certain visibility in the namespace to which the type belongs. Similarly, a member of of type has a certain visibility. You can state the visibility explicitly by giving a so-called visibility modifier, or you can rely on defaults. It is recommended always to use explicit visibility modifiers, because it reflects that you have made a conscious choice.

Overview and clarification of some visibility issues

  • Types in namespaces

    • Either public or internal

    • Default visibility: internal

  • Members in classes

    • Either private, public, internal, protected or internal protected

    • Default visibility: private

  • Visibility inconsistencies

    • A type T can be less accessible than a method that returns a value of type T

/user/normark/oop-csharp-1/sources/c-sharp/visibility/visibility.csAn illustration of the 'Inconsistent Accessibility' problem. This program is explained

/user/normark/oop-csharp-1/sources/c-sharp/visibility/visibility-ok.csSolution to the problem.

Read more about visibility issues - in particular 'inconsistent accessibility' - in the text book version of this material.