Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "<employee>" mean in the following code: List<Employee><employee> employees = new List<Employee><employee>();

I am reading an MVC 5 tutorial (Learn MVC Project in 7 days – Day 2). It says to use this code:

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

I get a red underline. I understand I am trying to create a list of type Employee. (There is an Employee class.) But why don't I do it like this:

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

What does the <employee> part of the code do? Why do I need it? It's just giving me a red underline. Maybe I need to upgrade to MVC 5 from MVC 4? I'm using Visual Studio 2012 (MVC 4).

like image 369
Danny Avatar asked Dec 09 '22 02:12

Danny


2 Answers

This is a typo in the tutorial. You can check here that creating a List has no implementations of List<type><othertype>.

You may pass a int32 value or IEnumerable<T> which will specify your list size, however List<T><T> simply does not compile.

Edit: As pointed out in the comments by Ant P, nothing in C# allows for Anything<T><T>, so if you ever run across that, it will not compile.

like image 134
Daniel Hoffmann-Mitscherling Avatar answered Dec 10 '22 14:12

Daniel Hoffmann-Mitscherling


It's a typo in the tutorial.

You can read about Generics here.

The correct code would be as you said yourself. You're just creating a new list which can only hold employee objects.

like image 32
Ric .Net Avatar answered Dec 10 '22 15:12

Ric .Net