initialize a two-dimensional rectangular array, and use the array properties and methods : Array Dimension « Collections Data Structure « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Collections Data Structure » Array DimensionScreenshots 
initialize a two-dimensional rectangular array, and use the array properties and methods
initialize a two-dimensional rectangular array, and use the array properties and methods

/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
  Example10_7.cs illustrates how to initialize
  a two-dimensional rectangular array, and use the
  array properties and methods
*/

using System;

public class Example10_7
{

  public static void Main()
  {

    // create and initialize the names array
    string[,names =
    {
      {"Jason""Marcus""Price"},
      {"Steve""Edward""Smith"},
      {"Cynthia""Ann""Williams"},
      {"Gail""Patricia""Jones"},
    };

    // display the Rank and Length properties of the names array
    Console.WriteLine("names.Rank (number of dimensions) = " + names.Rank);
    Console.WriteLine("names.Length (number of elements) = " + names.Length);

    // use the GetLength() method to get number of elements
    // in each dimension of the names array
    int numberOfRows = names.GetLength(0);
    int numberOfColumns = names.GetLength(1);
    Console.WriteLine("Number of rows = " + numberOfRows);
    Console.WriteLine("Number of columns = " + numberOfColumns);

    // display the elements of the names array
    for (int row = 0; row < numberOfRows; row++)
    {
      for (int column = 0; column < numberOfColumns; column++)
      {
        Console.WriteLine("names[" + row + ", " + column + "] = " +
          names[row, column]);
      }
    }

  }

}

           
       
Related examples in the same category
1.Demonstrate a two-dimensional arrayDemonstrate a two-dimensional array
2.Sum the values on a diagonal of a 3x3x3 matrixSum the values on a diagonal of a 3x3x3 matrix
3.Initialize a two-dimensional arrayInitialize a two-dimensional array
4.Demonstrate jagged arraysDemonstrate jagged arrays
5.Use the Length array property on a 3-D arrayUse the Length array property on a 3-D array
6.Call GetLength for two dimenional array
7.Demonstrate Length with jagged arraysDemonstrate Length with jagged arrays
8.illustrates the use of a two-dimensional rectangular arrayillustrates the use of a two-dimensional rectangular array
9.the use of a three-dimensional rectangular arraythe use of a three-dimensional rectangular array
10.the use of a jagged arraythe use of a jagged array
11.Uses a two-dimensional array to store grades for studentsUses a two-dimensional array to store grades for students
12.Uses a jagged array to store sales figuresUses a jagged array to store sales figures
13.Multidimensional and Jagged Arrays:Jagged ArraysMultidimensional and Jagged Arrays:Jagged Arrays
14.Multi dimensional Arrays 1Multi dimensional Arrays 1
15.Catch OutOfMemoryException
16.Catch IndexOutOfRangeException Exception
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.