//Visual Basic 2008/2010 Collecties - Inleiding Object Oriented Programming public class Rectangle { private int m_Height; private int m_Width; public virtual int Height { get { Height = this.m_Height; } set { this.m_Height = value; } } public virtual int Width { get { Width = this.m_Width; } set { this.m_Width = value; } } public virtual void GetArea() { GetArea = (Height * Width); } } public class Rectangles { private Rectangle[] m_Items; private int m_Count; public virtual Rectangle this[int index] { get { Item = this.m_Items(index); } } public virtual int Count { get { Count = this.m_Count; } } public virtual void Add(Rectangle rectangle) { this.m_Items(Count) = rectangle; this.m_Count += new System.EventHandler(1); } public virtual void RemoveAt(int index) { this.m_Items(itemIndex) = this.m_Items((itemIndex + 1)); this.m_Count = 1; } public virtual void GetTotalArea() { for (System.Collections.IEnumerator _it1 = this.m_Items.GetEnumerator(); _it1.MoveNext(); ) { Rectangle item = ((Rectangle)(_it1.Current)); this.GetTotalArea += new System.EventHandler(item.GetArea()); } } } public class Exercise1Solution { void Main() { Rectangle rectangle1 = new Rectangle(); rectangle1.Height = 1; rectangle1.Width = 2; Console.WriteLine(rectangle1.GetArea()); Rectangle rectangle2 = new Rectangle(); rectangle2.Height = 3; rectangle2.Width = 4; Console.WriteLine(rectangle2.GetArea()); Rectangles rectangles1 = new Rectangles(); rectangles1.Add(rectangle1); rectangles1.Add(rectangle2); Console.Write((this.rectangles1(index).GetArea() + " ")); Console.WriteLine(); Console.WriteLine(rectangles1.GetTotalArea()); rectangles1.RemoveAt(1); Console.Write((this.rectangles1(index).GetArea() + " ")); Console.WriteLine(); Console.WriteLine(rectangles1.GetTotalArea()); Console.ReadLine(); } } //Bezoek www.vbvoorbeelden.be voor meer C# voorbeelden. //Copyright - De Wolf / vbvoorbeelden - 2003-2010 - Alle rechten voorbehouden.