//C# Lineair Zoeken in Arrays Arrays public class LinearSearch { void Main() { int @base = 2; int count = 10; int upperbound = (count - 1); int[] numbers = new int[0]; int index; this.numbers(index) = ((index + 1) * @base); int number; bool found = false; bool exhausted = false; index = -1; for (; (found || exhausted); ) { this.index += new System.EventHandler(1); found = (this.numbers(index) == number); exhausted = (index == upperbound); } if (found) { Console.Write(((number + " found at index ") + index)); } else { Console.Write((number + " not found")); } if (exhausted) { Console.WriteLine(", search exhausted"); } else { Console.WriteLine(", search not exhausted"); } Console.ReadLine(); } } public class ExerciseTask { void Main() { int count = 3; string[] names; int[] zipCodes; Console.WriteLine("Zip Code ?"); string zipCode = Console.ReadLine(); Console.ReadLine(); } } public class ExerciseSolution { void Main() { int count = 3; string[] names; int[] zipCodes; Console.WriteLine("Zip Code ?"); string zipCode = Console.ReadLine(); bool found; bool exhausted; int index = -1; for (; (found || exhausted); ) { this.index += new System.EventHandler(1); found = (this.zipCodes(index) == zipCode); exhausted = (index == (count - 1)); } if (found) { Console.WriteLine(this.names(index)); } else { Console.WriteLine("City not found."); } Console.ReadLine(); } } public class IndexOf { void Main() { int @base = 2; int count = 10; int upperbound = (count - 1); int[] numbers = new int[0]; int index; this.numbers(index) = ((index + 1) * @base); int number; index = Array.IndexOf(numbers, number); bool found = (index > -1); if (found) { Console.WriteLine(((number + " found at index ") + index)); } else { Console.WriteLine((number + " not found")); } Console.ReadLine(); } } //Bezoek www.vbvoorbeelden.be voor meer C# voorbeelden. //Copyright - De Wolf / vbvoorbeelden - 2003-2010 - Alle rechten voorbehouden.