//C# Inleiding Arrays Arrays public class Example1 { void Main() { int value1; int value2; int value3; int sum; Console.WriteLine("Value 1 ?"); value1 = Console.ReadLine(); this.sum += new System.EventHandler(value1); Console.WriteLine("Value 2 ?"); value2 = Console.ReadLine(); this.sum += new System.EventHandler(value2); Console.WriteLine("Value 3 ?"); value3 = Console.ReadLine(); this.sum += new System.EventHandler(value3); Console.Write(value1); Console.Write(" + "); Console.Write(value2); Console.Write(" + "); Console.Write(value3); Console.Write(" = "); Console.Write(sum); Console.ReadLine(); } } public class Example2 { void Main() { int[] values = new int[0]; int sum; Console.WriteLine("Value 1 ?"); this.values(0) = Console.ReadLine(); this.sum += new System.EventHandler(this.values(0)); Console.WriteLine("Value 2 ?"); this.values(1) = Console.ReadLine(); this.sum += new System.EventHandler(this.values(1)); Console.WriteLine("Value 3 ?"); this.values(2) = Console.ReadLine(); this.sum += new System.EventHandler(this.values(2)); Console.Write(this.values(0)); Console.Write(" + "); Console.Write(this.values(1)); Console.Write(" + "); Console.Write(this.values(2)); Console.Write(" = "); Console.Write(sum); Console.ReadLine(); } } public class Example3 { void Main() { int[] values = new int[0]; int sum; int index; Console.WriteLine((("Value " + (index + 1)) + " ?")); this.values(index) = Console.ReadLine(); this.sum += new System.EventHandler(this.values(index)); Console.Write(this.values(0)); Console.Write(" + "); Console.Write(this.values(index)); Console.Write(" = "); Console.Write(sum); Console.ReadLine(); } } public class Example4 { void Main() { Console.WriteLine("Count ?"); int count = Console.ReadLine(); int[] values = new int[0]; int sum; int index; Console.WriteLine((("Value " + (index + 1)) + " ?")); this.values(index) = Console.ReadLine(); this.sum += new System.EventHandler(this.values(index)); Console.Write(this.values(0)); Console.Write(" + "); Console.Write(this.values(index)); Console.Write(" = "); Console.Write(sum); Console.ReadLine(); } } public class Example5 { void Main() { int[] values = new int[0]; bool[] conditions = new bool[0]; int index; Console.WriteLine(this.values(index)); Console.WriteLine(this.conditions(index)); Console.ReadLine(); } } public class Exercise1Solution { void Main() { int count = 5; int upperbound = (count - 1); int[] values = new int[0]; int index; Console.Write((("Value " + (index + 1)) + " : ")); this.values(index) = Console.ReadLine(); Console.WriteLine(((((("Element " + (index + 1)) + " ( at index ") + index) + " ) : ") + this.values(index))); Console.ReadLine(); } } public class Exercise2Solution { void Main() { Console.Write("Count : "); int count = Console.ReadLine(); int upperbound = (count - 1); int[] values = new int[0]; int index; int highestValueIndex; Console.Write((("Value " + (index + 1)) + " : ")); this.values(index) = Console.ReadLine(); if ((this.values(highestValueIndex) < this.values(index))) { highestValueIndex = index; } Console.WriteLine((((((("Highest Value : " + this.values(highestValueIndex)) + " ( element ") + (highestValueIndex + 1)) + " at index ") + highestValueIndex) + " )")); Console.ReadLine(); } } public class Exercise3Solution { void Main() { int[] values = new int[0]; int index; this.values(index) = (10 - index); Console.WriteLine(((((("element " + (index + 1)) + " ( index ") + index) + " ) : ") + this.values(index))); Console.ReadLine(); } } public class Exercise4Solution { void Main() { int count = 10; int upperbound = (count - 1); int[] values = new int[0]; int index; this.values(index) = (index + 1); Console.WriteLine(((((("element " + (index + 1)) + " ( index ") + index) + " ) : ") + this.values(index))); Console.WriteLine(); int backup; backup = this.values(index); this.values(index) = this.values((upperbound - index)); this.values((upperbound - index)) = backup; Console.WriteLine(((((("element " + (index + 1)) + " ( index ") + index) + " ) : ") + this.values(index))); Console.ReadLine(); } } public class Exercise5Solution { void Main() { int count = 10; int upperbound = (count - 1); int[] values = new int[0]; int index; this.values(index) = (index + 1); Console.WriteLine(((((("element " + (index + 1)) + " ( index ") + index) + " ) : ") + this.values(index))); Console.WriteLine(); int backup = this.values(0); this.values(index) = this.values((index + 1)); this.values(upperbound) = backup; Console.WriteLine(((((("element " + (index + 1)) + " ( index ") + index) + " ) : ") + this.values(index))); Console.ReadLine(); } } public class Exercise6Solution { void Main() { int count = 10; int upperbound = (count - 1); int[] values1 = new int[0]; int[] values2 = new int[0]; int[] values3 = new int[0]; int index; this.values1(index) = (index + 1); Console.WriteLine("Array 1 :"); Console.WriteLine(((((("element " + (index + 1)) + " ( index ") + index) + " ) : ") + this.values1(index))); Console.WriteLine(); this.values2(index) = (count - index); Console.WriteLine("Array 2 :"); Console.WriteLine(((((("element " + (index + 1)) + " ( index ") + index) + " ) : ") + this.values2(index))); Console.WriteLine(); if ((this.values1(index) >= this.values2(index))) { this.values3(index) = this.values1(index); } else { this.values3(index) = this.values2(index); } Console.WriteLine("Array 3 :"); Console.WriteLine(((((("element " + (index + 1)) + " ( index ") + index) + " ) : ") + this.values3(index))); Console.WriteLine(); Console.ReadLine(); } } public class Exercise7Solution { void Main() { Console.Write("Count : "); int count = Console.ReadLine(); if ((count <= 0)) { Console.WriteLine("Error : Minimum count 1."); } else { int upperbound = (count - 1); int[] fibonacci = new int[0]; int index; this.fibonacci(0) = 1; if ((count > 1)) { this.fibonacci(1) = 1; this.fibonacci(index) = (this.fibonacci((index - 1)) + this.fibonacci((index - 2))); } Console.Write((this.fibonacci(index) + " ")); } Console.ReadLine(); } } //Bezoek www.vbvoorbeelden.be voor meer C# voorbeelden. //Copyright - De Wolf / vbvoorbeelden - 2003-2011 - Alle rechten voorbehouden.