ex-09-02

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

TXT
51
字号
//Example 09-02: Using foreach

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


      private int size;
   }
   public class Tester
   {
      static void Main()
      {
         int[] intArray;
         Employee[] empArray;
         intArray = new int[5];
         empArray = new Employee[3];

         // populate the array
         for (int i = 0;i<empArray.Length;i++)
         {
            empArray[i] = new Employee(i+10);
         }
           
         foreach (int i in intArray)
         {
            Console.WriteLine(i.ToString());
         }

         foreach (Employee e in empArray)
         {
            Console.WriteLine(e.ToString()); 
         }
      }
   }
}

⌨️ 快捷键说明

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