tags:

views:

80

answers:

3

Given the code block below (source: http://www.asp.net/learn/mvc/tutorial-31-cs.aspx)... I receive this error: Using the generic type 'System.Collections.Generic.List' requires '1' type arguments

I can pacify this by simply modifying my declaration to read as: var groups = new List<string>(); Is this just a case of invalid syntax in the example code? I ask here, however, because I've run into this more than once and am wondering if there's some kind of VS.NET "strictness setting" that might be at play in my VS environment.

public class GroupController : Controller
{
    public ActionResult Index()
    {
        var groups = new List();
        return View(groups);
    }

    /// another example...
 Assert.IsInstanceOfType(result.ViewData.Model, typeof(IEnumerable));  // same error

 Assert.IsInstanceOfType(result.ViewData.Model, typeof(IEnumerable<string>)); // corrected

}
+1  A: 

It's an error in the linked web page. If you look at the HTML source you can see that there is an argument to the generic type parameter:

namespace ContactManager.Controllers
{
    public class GroupController : Controller
    {
        public ActionResult Index()
        {
            var groups = new List<Group>();
            return View(groups);
        }

    }
}

Same applies to the example above (or, in your question, below):

// Assert
Assert.IsInstanceOfType(result.ViewData.Model, typeof(IEnumerable<Group>));
dtb
Firebug did not show me that! ;p
leppie
+1  A: 

Yes, this appears to be a bug in the way the sample code is being rendered into HTML

JaredPar
+1  A: 

Yes, this is invalid syntax in the sample code as rendered.

One point which is adding confusion is the use of both IEnumerable and IEnumerable<string> in the code. This is okay, because IEnumerable and IEnumerable<T> are different types. The first is nongeneric, the second is generic.

Compare that with List<T> - there isn't a nongeneric List type. (The closest equivalent is ArrayList.)

Jon Skeet
Thanks to all the quick responses! I should clarify that those two IEnumerable lines are ones that I added just for brevity.
Clay