本代码通过ICollection接口的count属性来输出其元素数量
using System; using System.Collections; public class CountArray { public static void Main() { string[] strings = {"Ajax", "Atlas"}; DisplayCollectionProperty (strings); } public static void DisplayCollectionProperty (ICollection iCollection) { Console.WriteLine ("Count = {0}", iCollection.Count); } }