A two dimensional array of objects : Array object « Data Structure « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Data Structure » Array object 
11.3.4.A two dimensional array of objects
using System;

public class Employee
{
  public string name;
  public int no;

  public Employee(string name,int no)
  {
    this.name = name;
    this.no = no;
  }
}


class MainClass
{

  public static void Main()
  {
    Employee[,,empArray = new Employee[1053];

    empArray[132new Employee("S"3);
    empArray[412new Employee("A"9);

    Console.WriteLine("empArray.Rank (number of dimensions) = " + empArray.Rank);
    Console.WriteLine("empArray.Length (number of elements) = " + empArray.Length);

    for (int x = 0; x < empArray.GetLength(0); x++)
    {
      for (int y = 0; y < empArray.GetLength(1); y++)
      {
        for (int z = 0; z < empArray.GetLength(2); z++)
        {
          if (empArray[x, y, z!= null)
          {
            Console.WriteLine("empArray[" + x + ", " + y + ", " + z +"].name = " + empArray[x, y, z].name);
            Console.WriteLine("empArray[" + x + ", " + y + ", " + z +"].no = " + empArray[x, y, z].no);
          }
        }
      }
    }

  }

}
empArray.Rank (number of dimensions) = 3
empArray.Length (number of elements) = 150
empArray[1, 3, 2].name = S
empArray[1, 3, 2].no = 3
empArray[4, 1, 2].name = A
empArray[4, 1, 2].no = 9
11.3.Array object
11.3.1.string arrays
11.3.2.Use object to create a generic array.
11.3.3.Use the Sort() method to sort the elements in a char array
11.3.4.A two dimensional array of objects
11.3.5.Arrays of Objects
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.