ex-09-12

来自「Programming Csharp Source Code(代码) Prog」· 代码 · 共 69 行

TXT
69
字号
// Example 09-12: Working with an ArrayList

namespace Programming_CSharp
{
   using System;
   using System.Collections;
  
   // a simple class to store in the array
   public class Employee
   {
      public Employee(int empID)
      {
         this.empID = empID;
      }
      public override  string ToString()
      {
         return empID.ToString();
      }
      public int EmpID
      {
         get
         {
            return empID;
         }
         set
         {
            empID = value;
         }
      }

      private int empID;
   }
   public class Tester
   {
      static void Main()
      {
         ArrayList empArray = new ArrayList();
         ArrayList intArray = new ArrayList();

         // populate the array
         for (int i = 0;i<5;i++)
         {
            empArray.Add(new Employee(i+100));
            intArray.Add(i*5);
         }
         
         // print all the contents
         for (int i = 0;i<intArray.Count;i++)
         {
            Console.Write("{0} ", intArray[i].ToString());
         }

         Console.WriteLine("\n");

         // print all the contents of the button array
         for (int i = 0;i<empArray.Count;i++)
         {
            Console.Write("{0} ", empArray[i].ToString());
         }

         Console.WriteLine("\n");
         Console.WriteLine("empArray.Capacity: {0}",
            empArray.Capacity);
      }
   }
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?