Code
using System;
using System.Collections;//注意using Collections
using System.Collections.Generic;
using System.Text;
namespace CollectionTest
{
class Program
{
static void Main(string[] args)
{
WordCollection words = new WordCollection();
foreach (string value in words)
{
Console.WriteLine(value);
}
Console.Read();
}
}
public class WordCollection : ICollection
{
private string[] _list;
private object _root = new object();
public WordCollection()
{
_list = new string[] { "You", "and", "me", "!" };
}
#region ICollection Members
public void CopyTo(Array array, int index)
{
_list.CopyTo(array, index);
}
public int Count
{
get { return _list.Length; }
}
public bool IsSynchronized
{
get { return true; }
}
public object SyncRoot
{
get { return _root; }
}
#endregion
#region IEnumerable Members
public IEnumerator GetEnumerator()
{
return _list.GetEnumerator();
}
#endregion
}
}