.NET
  Home arrow .NET arrow Page 3 - .NET Type System, Part II
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
.NET

.NET Type System, Part II
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 36
    2005-03-28

    Table of Contents:
  • .NET Type System, Part II
  • C# Classes
  • Using Arrays
  • Single-Dimension Arrays
  • Multi-Dimension Arrays
  • C# Strings
  • Boxing Operation

  • 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


    .NET Type System, Part II - Using Arrays


    (Page 3 of 7 )

    You declare an array in C# by placing empty square brackets after the type of the array, followed by the variable name that will hold the reference to the array:

    int[] Numbers;

    It's different from the syntax used in C++, where you put the square brackets after the variable name. Note that you need to create the array using the new operator in order to use it:

    Numbers = new int[6];

    This statement simply creates an array of six integers on the Managed Heap, returns the reference, and assigns it to the variable Numbers. You can declare and instantiate the array in one statement:

    int[] Numbers = new int[6];

    You can initialize the elements of the array within the same declaration statement:

    int[] Numbers = {10,29,33,47,51,64};

    You can also initialize the array after you instantiate it:

    int[] Numbers = new int[6];
    Numbers[0] = 10;
    Numbers[1] = 29;
    Numbers[2] = 33;
    Numbers[3] = 47;
    Numbers[4] = 51;
    Numbers[5] = 64;

    We initialized the array by initializing each element separately. As you can see, you access each element in the array through its index, so to access the first element of the array you write the code Numbers[0], and so on. Also note that .NET arrays are zero-based; this is an inherited feature from the base class System.Array, which you derive implicitly each time you create an array in C#.

    When you declare an array of value types, the elements will contain the actual data, but when you declare an array of reference types, the array will contain references to memory addresses where the data is stored. C# provides you with single-dimension arrays, multi-dimension arrays and jagged arrays.

    More .NET Articles
    More By Michael Youssef


     

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek