⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex-09-12

📁 Programming Csharp Source Code(代码) Programming Csharp Source Code
💻
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -