C#
  Home arrow C# arrow Page 4 - C# Simplified, part 3
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? 
C#

C# Simplified, part 3
By: Anand Narayanaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 11
    2005-05-17

    Table of Contents:
  • C# Simplified, part 3
  • Displaying numbers in different formats
  • Display date and time in different formats
  • Arrays
  • Using Array.Rank
  • Enumerations

  • 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


    C# Simplified, part 3 - Arrays


    (Page 4 of 6 )

    Arrays are not new to C#. They exist in all programming languages such as C, C++ and Java. They enable you to store a list of items of similar data type. For example, to store the age of students you can use an array of type integer. Similarly, if you have to store their names, addresses, and so forth, you can use a string data type.

    In C#, arrays are derived from the Array class found in the System namespace. This class contains lot of properties and methods, which you can manipulate for your various programming tasks.

    Arrays in C# are declared in the same manner as in Java and C++, and they can be either single or multi-dimensional. Listing 3.5 declares a single dimensional array of type integer and with a dimension of 10. Dimension indicates the number of array elements which you can store in the variable named x.

    Listing 3.5

    int[] x = new int[10]

    Arrays can also be declared as in the code given in listing 3.6:

    Listing 3.6

    int[] x = {2,3,4,5,6}

    The above code snippet stores five integer values. In C#, the index position for the first element is zero. In listing 3.7, an array variable is declared with four values and they are printed using the for loop.

    Listing 3.7

    using System;

    class ArraysDemo

    {

    public static void Main()

    {

    int[] x = {10,20,30,40,50};

    for(int i = 0; i<=4;i++)

    {

    Console.WriteLine(x[i]);

    }

    }

    }

    Instead of supplying the condition inside the for loop, you can apply the Length property of the Array class to determine the dimensions of an array, as shown in listing 3.8:

    Listing 3.8

    using System;

    class ArraysDemo2

    {

    public static void Main()

    {

    int[] x = {10,20,30,40,50};

    for(int i = 0; i<x.Length;i++)

    {

    Console.WriteLine(x[i]);

    }

    }

    }

    C# also supports so called multi-dimensional arrays, as shown in the code snippets given below:

    // Three dimensional array (Count number of commas and add 1 to it)

    int[,,] x

    // Two dimensional array

    int[,] y

    More C# Articles
    More By Anand Narayanaswamy


     

    C# ARTICLES

    - Working with Dates and Times in C#
    - Generics, Dictionaries, and More
    - More About Generics
    - Working with C# Collections
    - Generics
    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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