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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With