Iterate over an array using the IList interface

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
C# Code Snippets

C# Source Code Bank

See also …
edit

This C# code snippet iterates through array values using the Count property of the IList interface.

using System;
using System.Collections;
 
public class IterateArray
{
 
   public static void Main()
   {
      DisplayList (new int[3]    {5, 10, 15});
      DisplayList (new string[3] {"a", "b", "c"});
   }
    
   public static void DisplayList (IList iList)
   {
      for (int i = 0; i < iList.Count; i++)
      {
        Console.Write ("{0} ", iList[i]);
      }
      Console.WriteLine();
   }
}


 IList iteration example (program output)
5 10 15
a b c

Personal tools