Cannot implicitly convert type 'System.Collections.Generic.IEnumerable GroupingLayer to 'System.Collections.IList'

StackOverflow https://stackoverflow.com/questions/21988295

문제

I have this code :

var selected = from c in myList group c by c.MainTitle into n select new GroupingLayer<string, MyObject>(n);
            longListSelector.ItemsSource = selected; //Error here


public class GroupingLayer<TKey, TElement> : IGrouping<TKey, TElement>
        {

            private readonly IGrouping<TKey, TElement> grouping;

            public GroupingLayer(IGrouping<TKey, TElement> unit)
            {
                grouping = unit;
            }

            public TKey Key
            {
                get { return grouping.Key; }
            }

            public IEnumerator<TElement> GetEnumerator()
            {
                return grouping.GetEnumerator();
            }

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return grouping.GetEnumerator();
            }
        }

What does its trying to tell me ?, how to solve this ?

I am Working on windows Phone 8 application.

도움이 되었습니까?

해결책

It's telling you that longListSelector.ItemsSource is of type IList, but the value stored in selected is an IEnumerable, and you can't assign one to the other.

Try calling ToList():

var selected = (from c in myList
                group c by c.MainTitle into n
                select new GroupingLayer<string, MyObject>(n)).ToList();

longListSelector.ItemsSource = selected;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top