Question

What is difference to the controller that gets the return with repect to rendering the List?

In Linq dataContext:

public IList<Response> GetResponses(int ID)
    {
        var responses = from r in this.Responses where r.ID == ID orderby r.Date select r;

        return responses.ToList();
    }

OR

 public List<Response> GetResponses(int ID)
    {
        var responses = from r in this.Responses where r.ID == ID orderby r.Date select r;

        return responses.ToList();
    }
Was it helpful?

Solution

I doubt there's much difference to the controller but you should probably try to reveal as little information as possible about the private data of your classes. This means exposing interfaces rather than concrete types and using the interface that exposes the minimum amount of information the client will need to operate on the data.

If the controller only needs an IEnumerable<Response> then you should consider making that the return type of GetResponses.

OTHER TIPS

The difference is that the controller won't need to be updated if you change your List implementation if you use the IList interface. It's probably not that big of a deal unless you are planning to make your library available to others. In that case the abstraction is probably justified as you won't be the only one having to update your code if you make the change.

Consider returning an array, consider accepting IEnumerable as a parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top