Sample with line numbers and alternating line background below.
/************************************************* * This sample illustrates how to use an ArrayList * and a foreach loop. * (from the quickstart tutorials) **************************************************/ using System; using System.Collections; class ListSample { public static void Main(String[] args) { //create the arraylist and add the items ArrayList fruit = new ArrayList(); fruit.Add("Apple"); fruit.Add("Pear"); fruit.Add("Orange"); fruit.Add("Banana"); //loop through the arraylist elements foreach (String item in fruit) { Console.WriteLine(item); } Console.WriteLine ("\nPress Return to exit."); Console.Read(); } }
1: /*************************************************
2: * This sample illustrates how to use an ArrayList
3: * and a foreach loop.
4: * (from the quickstart tutorials)
5: **************************************************/
6: using System;
7: using System.Collections;
8:
9: class ListSample
10: {
11: public static void Main(String[] args)
12: {
13: //create the arraylist and add the items
14: ArrayList fruit = new ArrayList();
15: fruit.Add("Apple");
16: fruit.Add("Pear");
17: fruit.Add("Orange");
18: fruit.Add("Banana");
19:
20: //loop through the arraylist elements
21: foreach (String item in fruit)
22: {
23: Console.WriteLine(item);
24: }
25:
26: Console.WriteLine ("\nPress Return to exit.");
27: Console.Read();
28: }
29: }
Comments: webmaster@manoli.net
Copyright © 2008 manoli.net