两个结果集,一个“Observable<string>()   testone ”和"List<string>()  testtwo   ",testone 和testtwo 两者之间应该怎样转化???转化过程是不是很消耗资源???

解决方案 »

  1.   


    Observable<string>?你说的是 ObservableCollection<string>吧?就是遍历List<string>然后一个一个插入到集合里边去呗。至于你说的“消耗资源”,我不知道你说的是什么资源,不好随便下结论。做任何事都是需要消耗资源资源的,唯一不消耗资源的的做法就是什么都不做。所以还是要看懂你自己所需。
      

  2.   


    自己看吧:public ObservableCollection(List<T> list) : base((list != null) ? new List<T>(list.Count) : list)
    {
        this._monitor = new SimpleMonitor<T>();
        this.CopyFrom(list);
    }private void CopyFrom(IEnumerable<T> collection)
    {
        IList<T> items = base.Items;
        if ((collection != null) && (items != null))
        {
            using (IEnumerator<T> enumerator = collection.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    items.Add(enumerator.Current);
                }
            }
        }
    }
      

  3.   

    查了下定义 如果是ObservableCollection 那么这个类显式实现了IList接口 反正List<T>也是实现了IList<T>的 不如直接转化成IList<T>好了