0

Hi guys,
I'm looking into MVC and I'm reasing this tutorial http://www.asp.net/mvc/overview/older-versions/hands-on-labs/aspnet-mvc-4-fundamentals
I've got to the point of adding a model and the class they add is this:

public class StoreIndexViewModel
{
  public int NumberOfGenres { get; set; }
  public List<string> Genres { get; set; }
}

I'm not really familiar with this syntax public List<string> Genres and I was wondering if anybody can help me understanding this a bit better. They refer to it as a list of string, so why not use an array of strings? Is that also what they call a "generic"? How do I get values in that list of string and how do I get them out please?
thanks

3
Contributors
5
Replies
32
Views
2 Years
Discussion Span
Last Post by DaveAmour
0

Hi

This is indeed a Generic List.

You can create a List of anything eg List<Customer> or List<Invoice>

To Add things you just use:

var model = new StoreIndexViewModel();

model.Genres.Add("Horror");
model.Genres.Add("Romance");
model.Genres.Add("Drama");

You can pull them all out with things like:

foreach (var genre in mode.Genres)
{
    //Do something with genre here
}

Why is this better than an array? Many reasons. Check out this video:

https://www.youtube.com/watch?v=J9Cwi45UtZU

Edited by DaveAmour

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.