" in the following code: List employees = new List (); I am reading an MVC 5...">

Which means "<employee>" in the following code: List <Employee> <employee> employees = new List <Employee> <employee> ();

I am reading an MVC 5 tutorial online ( here ). It says to use this code:

 List<Employee><employee> employees = new List<Employee><employee>();

      

I am getting red underline. I understand that I am trying to create a list of type Employee (there is an Employee class). But why am I not doing this:

 List<Employee>employees = new List<Employee>();

      

What is he doing...

 <employee> 

      

... does a piece of code do? Why do I need it? It just gives me a red underline. Perhaps I need to migrate to MVC 5 from MVC 4? I am using Visual Studio 2012 (MVC 4)

+3


source to share


2 answers


This is a typo in the tutorial. You can check here that there are no implementations to create the list List<type><othertype>

.

You can pass in a value int32

or IEnumerable<T>

, which will indicate the size of your list, but it List<T><T>

just won't compile.



Edit: As pointed out in the comments from Ant P, nothing in C # allows it Anything<T><T>

, so if you ever run into this it won't compile.

+10


source


This is a typo in the tutorial.

You can read Generics here .



The correct code will be as you said yourself. You just create a new list that can only contain employee objects.

+3


source







All Articles