// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Linq; namespace E { public class Program { public static void TheLinqWay() { int[] numbers = { 5, 4, 3, 6, 2, 0 }; string[] people = { "John", "Ned", "Tom", "Ann", "Patrick", "Carla", "Lynda"}; var numbersPeople = from n in numbers select people[n]; string str_write; str_write = "People on random display:" + Environment.NewLine; foreach (var s in numbersPeople) { str_write += s.ToString() + System.Environment.NewLine; } Console.WriteLine(str_write); } public static void TheTraditionalWay() { int[] numbers = { 5, 4, 3, 6, 2, 0 }; string[] people = { "John", "Ned", "Tom", "Ann", "Patrick", "Carla", "Lynda"}; string[] numbersPeople = Array.ConvertAll(numbers, n => people[n]); string str_write = numbersPeople.Aggregate("People on random display:", (s1,s2) => s1 + Environment.NewLine + s2); Console.WriteLine(str_write); } public static void Main(string[] args) { TheLinqWay(); TheTraditionalWay(); } } }