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

Recommended Answers

All 5 Replies

You can probably google about 'php list vs array' and get what you want and maybe you will be more understand after go throught examples in this link: http://php.net/manual/en/function.list.php

Sorry, please do ignore my post. Thought it is in php section.

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

OK thanks for your help with that!

Youre welcome

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.