zoukankan      html  css  js  c++  java
  • 实现ICollection

    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
        }
    }
  • 相关阅读:
    C++getline()
    Financial Tsunami
    Exploring Matrix
    shuffle.java
    Java数组声明
    jpg与jpeg的区别在哪
    WinForm训练一_改变窗体大小
    ErrorProvider与CheckedListBox
    如何看待 SAE 在2014 年 3 月 24 日发生的的大面积宕机事故?
    一个技术青年的网络失足
  • 原文地址:https://www.cnblogs.com/jazzka702/p/1503258.html
Copyright © 2011-2022 走看看