Can't reference a method property

I'm trying to call a function

NextPrevious((List<Store>)model.Group.ToList(), 3, groupPage.Value, ref next, ref previous);

With the method definition being..

private void NextPrevious(List<Store> model, int numFields, int page, ref bool nextRef, ref bool previousRef)
{
    ...
}

But I get a cannot convert Group to Store error. model is a variable from a class which contains a list of Group objects and some more.

Group is also a subclass of the class Store.

I'm only checking basic List<> stuff inside the method, like method.Count or method.Skip() so if there's some easier way to do this, I'm all ears, I'm not calling any of the specific Store or Group methods.

Sorry if I posted too little information, I can post more if needed. Thanks!

Jon Skeet
people
quotationmark

A List<Group> is not a List<Store>. However, you can use a type argument to the ToList method to make it create a List<Store> instead:

NextPrevious(model.Group.ToList<Store>(), ...)

That's assuming you're using C# 4 or higher and .NET 4 or higher, so you can use the covariance of IEnumerable<T>.

people

See more on this question at Stackoverflow