Question

Why I can't define the LLSGroupsWithItems in the following example (it won't compile):

public class LLSGroupsWithItems<Group<T>> : ObservableCollection<Group<T>>
    {

    }

    public class Group<T> : ObservableCollection<T>
    {
        public Group(string name, IEnumerable<T> items)
        {
            this.Key = name;
            foreach (T item in items)
            {
                this.Add(item);
            }
        }

        public override bool Equals(object obj)
        {
            Group<T> that = obj as Group<T>;

            return (that != null) && (this.Key.Equals(that.Key));
        }

        public string Key
        {
            get;
            set;
        }
    }

The compiler error is:

Type parameter declaration must be an identifier not a type.

Long story:

I have seen an example on WindowsPhoneGeek about how to dynamically add items to a structure of a form ObservableCollection<ObservableCollection<T>>, but I want to encapsulte an automatic grouping functionality within the collection that my LongListSelector is bound to, so that I don't have to always look, what group to add a particular item to. For this, I suppose, I need to create a class I am trying to define, but C# limitations or something won't let me. Please explain why. Thanks.

Était-ce utile?

La solution

Shouldn't this

public class LLSGroupsWithItems<Group<T>> : ObservableCollection<Group<T>>
{
}

be written like this instead?

public class LLSGroupsWithItems<T> : ObservableCollection<Group<T>>
{
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top