C#
  Home arrow C# arrow Page 6 - Defining Member and Type Visibility
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 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 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
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Defining Member and Type Visibility - Type Visibility


    (Page 6 of 6 )

    Public Type

    Creating a public type means that the type is accessed from other types in the current assembly as well as other assemblies. This is useful when you are creating a code library. Here is an example:


    public class Book

    {

    private string title;

    private string author;

    private string ISBN;

    }


    Since the Book class is public, it can be accessed from other assemblies. The users of this assembly can create Book objects, inherit from the Book class, and so on…

    Internal Type

    Internal types, on the other hand, can be used only by the assembly in which they are defined. So, if we make the Book class internal, other assemblies cannot in any way interact with the Book class:


     internal class Book

    {

    private string title;

    private string author;

    private string ISBN;

    }


    Please note that the default access modifier for a type is internal. In other words, if you do not specify the access modifier, it will be internal. So the following declarations are identical:


     class Book {...}


    internal class Book {...}


    Conclusion 

    When creating types, it is very important to pay special attention to the type member’s visibility. Declaring a member private makes it accessible only to the defining class. Declaring the member public, on the other hand, makes it accessible by any type. When it comes to inheritance, try to keep members protected so that only subclasses can access them. As far as building your own libraries, internal and protected internal members come handy.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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

    C# ARTICLES

    - Color Transformation in C# GDI+ Programming
    - Exceptions in C#
    - Overriding versus Overloading
    - 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





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