1
using System;2
using System.Collections.Generic;3
using System.Linq;4
using System.Text;5
using System.Collections;6

7
namespace ConsoleApplication28


{9
public class ListBoxList : IEnumerable<string>10

{11
private string[] strings;12
private int ctr = 0;13
//Enumerable class can return an enumerator14
public IEnumerator<string> GetEnumerator()15

{16
foreach (string s in strings)17

{18
yield return s;19
}20
}21
//Explicit interface implemention22
IEnumerator IEnumerable.GetEnumerator()23

{24
return GetEnumerator();25
}26
//initialize the listbox with string27
public ListBoxList(params string[] initialString)28

{29
strings = new String[8];30
//copy the strings passed into the constructor31
foreach (string s in initialString)32

{33
strings[ctr++] = s;34
}35
}36
//add a single string to the end of the listbox37
public void Add(string theString)38

{39
strings[ctr] = theString;40
ctr++;41
}42
//allow array-like access43
public string this[int index]44

{45

46
get47

{48
if (index < 0 || index >= strings.Length)49

{ 50
//handle the index51
} return strings[index];52
}53
set54

{55
strings[index] = value;56
}57
}58
//publish howmany strings you holds59
public int GetEnmEntries()60

{61
return ctr;62
}63
}64
class Program65

{66
static void Main(string[] args)67

{68
//create a new listboxlist and initalize 69
ListBoxList lbt = new ListBoxList("hello","world");70
lbt.Add("Who");71
lbt.Add("Is");72
lbt.Add("Douglas");73
lbt.Add("Adams");74
string subst = "Universe";75
lbt[1] = subst;76
//accexx the listboxlist77
foreach (string s in lbt)78

{79
Console.WriteLine(s); 80
}81

82
Console.ReadKey();83
}84
}85
}86
