Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have an object-model "MovieInfo" class, which have the property "cast". here cast is a List of string values.
I want to get all the cast name from list<movie> and add it to comboBox items..
So, I tried:

C#
List<MoviesInfo> paraMovies=BLLMovies.MoviesManipulation.MoviesList;
 castTSCombo.Items.AddRange(paraMovies.Where(m=>m.Cast.Count>0).Select(m=>m.Cast.ToArray()).ToArray());


but its return "System.String[]" not the individual cast name..

MovieInfo class:
C#
public class MoviesInfo
    {

        public int ID { get; set; }
        public string Name { get; set; }
        public string review { get; set; }
        public List<string> Cast { get; set; }
        public int Rating { get; set; }

    }


how to get all the cast name from List<movieinfo>, so I can add it to the comboBox Items?

thanks in advanced..
Regards:
Jayanta.
Posted
Comments
Sergey Alexandrovich Kryukov 10-Aug-15 0:40am    
It makes no sense, because your data is not string data. Avoid working with strings representing data instead of data itself.
—SA
JayantaChatterjee 10-Aug-15 0:57am    
Sorry I don't understand..
actually in the cast field have values like:
List <string > cast=new List < string > ();
cast.Add( Marc Silverstein);
cast.Add(Abby Kohn);
cast.Add(Jason Katims);

this is for one movie, and there is more than one movie which have the multiple cast in it. I want to get all the cast name from all the movies name..

How to do that?
Sergey Alexandrovich Kryukov 10-Aug-15 1:06am    
All right, a bit simpler: don't do it.
If you want to know why, see above.
See also: Unhappy Inquirer or Is the Abuse the Main Purpose of Programming?.
—SA

use SelectMany
C#
paraMovies.Where(m=>m.Cast.Any()).SelectMany(m=>m.Cast).ToArray()
 
Share this answer
 
Comments
sreeyush sudhakaran 10-Aug-15 1:47am    
Yes..it works
JayantaChatterjee 10-Aug-15 1:47am    
thank you sir..
DamithSL 10-Aug-15 1:52am    
You are welcome!
Tried DamithSL solution and seems works fine :)

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;



namespace WindowsFormsApplication1
{
    public class MoviesInfo
    {

        public int ID { get; set; }
        public string Name { get; set; }
        public string review { get; set; }
        public List<string> Cast { get; set; }
        public int Rating { get; set; }

    }

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<moviesinfo> paraMovies = new List<moviesinfo>();
            for (int i = 0; i < 5; i++)
            {
                MoviesInfo oMoviesInfo = new MoviesInfo();
                oMoviesInfo.Cast = new List<string>();
                oMoviesInfo.ID = i;
                oMoviesInfo.Name = "Movie_" + i.ToString();
                oMoviesInfo.review = "Rating:" + i.ToString();
                oMoviesInfo.Rating = i;
                oMoviesInfo.Cast.Add(oMoviesInfo.Name + "_" + "Cast1");
                oMoviesInfo.Cast.Add(oMoviesInfo.Name + "_" + "Cast2");
                oMoviesInfo.Cast.Add(oMoviesInfo.Name + "_" + "Cast3");
                oMoviesInfo.Cast.Add(oMoviesInfo.Name + "_" + "Cast4");

                paraMovies.Add(oMoviesInfo);
            }

            var items = paraMovies.Where(m => m.Cast.Any()).SelectMany(m => m.Cast).ToArray();

            castTSCombo.Items.AddRange(items);


        }



    }
}

</string></moviesinfo></moviesinfo><>
 
Share this answer
 
v3
Comments
JayantaChatterjee 10-Aug-15 1:59am    
thanks ....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900