8
Groups of Objects, continued
lCollections
l
l /* Create and sum integer sequence collection */
l IntegerSequence Sequence=new IntegerSequence(
l int.Parse(textBox3.Text),int.Parse(textBox4.Text));
l long sum=0;
l foreach (int Integer in Sequence) sum=sum+Integer;
l MessageBox.Show("Sum(integer sequence collection) from
l "+textBox3.Text.Trim()+" to "+textBox4.Text.Trim()+" = "+sum.ToString(),
l "Collection",MessageBoxButtons.OK, MessageBoxIcon.Information);
l
l public class IntegerSequence : IEnumerable
l {
l public int Start; public int End;
l public IntegerSequence(int Start, int End)
l {this.Start=Start; this.End=End;}
l public IEnumerator GetEnumerator()
l {return new SequenceCollection(this);}
l }
l