.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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries





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