Getting values from the list

Getting values from the list

Hello :)

I have spend a lot of time trying how to ask this question so you understand it, and I get the answer. I am so sorry if I failed :(

I am having lots of problems trying to access some elements of the list.

I have a class name Movie with this code;

 public class Movie
    {
        public string Id { get; set; }
               
        public string Title { get; set; }
        public string Description { get; set; }
        public DateTime? ReleaseDate { get; set; }  
       
        public List<Person> Directors { get; set; }
        public List<Person> Cast { get; set; }      
        public List<Person> Producers { get; set; }
        public List<Person> Writers { get; set; }
        public List<Person> MusicBy { get; set; }
        public List<Person> CastingBy { get; set; }
        public List<Person> SpecialEffects { get; set; }
        public List<Person> Stunts { get; set; }
        public List<Person> CostumeDesignBy { get; set; }

        public List<string> ProductionCompanies { get; set; }
        public List<string> Distributors { get; set; }
        public List<string> SpecialEffectsCompanies { get; set; }
        public List<string> OtherCompanies { get; set; }
       
        public List<string> Genres { get; set; }
        public List<string> Languages { get; set; }
        public string Rated { get; set; }

        public int Year { get; set; }
        public double UserRating { get; set; }
        public double Votes { get; set; }

        public Image Poster { get; set; }
        public string PosterUrl { get; set; }
        public bool HasTrailer { get; set; }
        public string TrailerUrl { get; set; }
       
        public List<string> KnownTitles { get; set; }
        public List<Movie> RecommendedFilms { get; set; }

        public int Runtime { get; set; }
        public string Tagline { get; set; }
             
        public bool IsTvSerie { get; set; }
        public List<int> Seasons { get; set; }
       
        public object Tag { get; set; }

}

As I understand it, it makes two kind of lists. One string Generic and another one based on class Person.

And here is the class Person

public class Person
    {

        public string Name { get; set; }
        public string Id { get; set; }
        public Image Photo { get; set; }
        public DateTime Birthday { get; set; }
        public string Biography { get; set; }
        public string Nominations { get; set; }
        public string Character { get; set; }

    }

Also there is lots of code behind that fills all those fields.

When I want to display from a list I can do it easy, without any problems.

But If I want to display a value from a list made from Person class, I do not know how to do it.

For example I am using this code:

Movie  M= new Movie();

textbox.Text = M.Title; // this is string list

And it works, I get the name of the movie. That is for generic string of string type.

How do I get the values from the list based on Person class? For example how do I get the values from "Cast"

Movie  M= new Movie();

textbox.Text = M.Cast.???????????      ; // this is Person list

// What do I put there?

When I debug the program, I can see that all the values are there, it is just issue how to get to them. Here is the screen shot that shows that all the values are there. Cast field is expanded in Screen Shot.

http://img63.imageshack.us/img63/8263/switchonthecode.jpg

Thank you for your time.

wexoni
06/26/2010 - 16:08

It's me again :)

i was thinking and thinking, and thought about LINQ.

This is code that I used with success to get that data:

  var Members= from actors in M.Cast


                          select new { actors.Name };

                       

            foreach (var result in Members)
            {
                MessageBox.Show(result.Name);
                glumci.Text = result.Name;
               
            }

 

VERY BIG quesito now, is this the proper way to do it?

Is there another better way?

thank you :)

reply

The Reddest
06/29/2010 - 09:46

M.Cast is already a collection, so you could just iterate it directly.

// Iterates through every Person in the movie's cast
// and appends their name to the textbox's Text property.
foreach(var person in M.Cast)
{
  textbox.Text += person.Name + " ";
}

reply

wexoni
07/06/2010 - 15:48

Thank you very much :)

reply

Add Comment

Put code snippets inside language tags:
[language] [/language]

Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]

See here for supported languages.

Javascript must be enabled to submit anonymous comments - or you can login.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.