请问Dictionary字典在声明的时候如何赋值
不用Add

解决方案 »

  1.   

    有一个构造函数的重载是传入一个实现了IDictionary接口的参数
      

  2.   


    class Program
    {
        static void Main(string[] args)
        {
            Test test = new Test();
            Dictionary<string, string> dic = new Dictionary<string, string>(test);          Console.ReadKey();
        }
    }class Test :IDictionary<string,string>
    {    #region IDictionary<string,string> 成员    public void Add(string key, string value)
        {
            throw new NotImplementedException();
        }    public bool ContainsKey(string key)
        {
            throw new NotImplementedException();
        }    public ICollection<string> Keys
        {
            get { throw new NotImplementedException(); }
        }    public bool Remove(string key)
        {
            throw new NotImplementedException();
        }    public bool TryGetValue(string key, out string value)
        {
            throw new NotImplementedException();
        }    public ICollection<string> Values
        {
            get { throw new NotImplementedException(); }
        }    public string this[string key]
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }    #endregion    #region ICollection<KeyValuePair<string,string>> 成员    public void Add(KeyValuePair<string, string> item)
        {
            throw new NotImplementedException();
        }    public void Clear()
        {
            throw new NotImplementedException();
        }    public bool Contains(KeyValuePair<string, string> item)
        {
            throw new NotImplementedException();
        }    public void CopyTo(KeyValuePair<string, string>[] array, int arrayIndex)
        {
            throw new NotImplementedException();
        }    public int Count
        {
            get { throw new NotImplementedException(); }
        }    public bool IsReadOnly
        {
            get { throw new NotImplementedException(); }
        }    public bool Remove(KeyValuePair<string, string> item)
        {
            throw new NotImplementedException();
        }    #endregion    #region IEnumerable<KeyValuePair<string,string>> 成员    public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
        {
            throw new NotImplementedException();
        }    #endregion    #region IEnumerable 成员    IEnumerator IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException();
        }    #endregion
    }
      

  3.   

    http://www.cnblogs.com/springyangwc/archive/2011/02/24/1964065.html 参考。