C#
  Home arrow C# arrow Defining Member and Type Visibility
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Defining Member and Type Visibility
By: Ayad Boudiab
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-16

    Table of Contents:
  • Defining Member and Type Visibility
  • Public Members
  • Private Members
  • Protected Members
  • Internal and Protected Internal Members
  • Type Visibility

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Defining Member and Type Visibility
    (Page 1 of 6 )

    This article provides an in-depth discussion of member and type visibility. It illustrates when and where to make a member either public or private, protected or internal. It even gives you tips to use when building your own libraries. Keep reading to find out more!

    Before we get started, let’s clarify some terms. Types are the building blocks of an object-oriented language, like C#. An application is a collection of these types interacting together to provide useful information. When we refer to types, we mean classes, structures, interfaces, enumerations, and delegates (these types will be explored in more detail in upcoming articles).

    A type, like a class, contains members. Example of members will be methods, fields, constructors, and so on…

    As stated earlier, an object-oriented application is a collection of types, and a type is a collection of members. When designing a type, a common question arises: should the user of the class (another developer for instance) have access to a specific field in the class, or should that field be privately owned and manipulated by the type? In other words, what is the visibility of each member of the class? The reason this is important is that you do not want the user of your class to change the state of a certain field to an unacceptable value and thus, make that instance of the class useless.

    Now that we've clarified the importance of member visibility, here is a summary of those visibilities before we explore them in more detail:


    public

    This marks the member as accessible from other classes.

    private

    This marks the member as accessible from only the class that defined the member. In C#, all members are private by default.

    protected

    This marks the member as accessible from the defining class, and any derived classes.

    internal

    This marks the member as accessible from other types in the same assembly.

    protected internal

    This marks the member as accessible from the current assembly or from types derived from the defining class in the current assembly.


    Note: C# uses the term ‘access modifier’ to describe the accessibility.

    More C# Articles
    More By Ayad Boudiab


       · Hello everyone,Welcome to my first article of the series of introduction to C# and...
     

    C# ARTICLES

    - Value Types and Reference Types
    - Defining Member and Type Visibility
    - Managing Files in C#
    - Working with Windows Registry in C#
    - Lossless Image Resizing in C#
    - Lossless Image Converting in C#
    - Creating an RSS Feed with ASP.Net Written in...
    - Polymorphism in C#
    - Inheritance in C#
    - C# Events Explained
    - C# Delegates Explained
    - C# StreamReader and StreamWriter Explained
    - C# FileStream Explained
    - A Look at C# File and FileInfo Classes
    - A Look at C# Directory and DirectoryInfo Cla...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway