locked
About Cast Conversion

    Question

  • public void LoadPersons()
            {
                //OnlineVideoDataContext context = new OnlineVideoDataContext(Constants.DatabaseConnectionString);
                List<CelebrityDetails> CastList = new List<CelebrityDetails>();
                CastList = Task.Run(async()=>await Constants.connection.Table<CastProfile>().ToListAsync()).Result.Distinct().Select(i => new CelebrityDetails() { PersonID = i.PersonID, PersonName = i.Name.ToLower(), Image = i.FlickrPersonImageUrl, Alphabet = i.Name.ToLower().Trim().Substring(0, 1) }).ToList();
                var Celebrities = from name in CastList
                                  where name.Alphabet != ""
                                  group name by name.Alphabet into c
                                  orderby c.Key
                                  select new Group<CelebrityDetails>(c.Key, c);
                listCelebrities.ItemsSource = Celebrities;
            }

    When i Execute this code it is giving me the Error mesg as

    Error 106 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<Social_Celebrities.Group<Social_Celebrities.CelebrityDetails>>' to 'System.Collections.IList'. An explicit conversion exists (are you missing a cast?) E:\lartProjects\Windows Phone 8\OnlineVideos\Social Celebrities\MainPage.xaml.cs 86 43 Social Celebrities

    Please help in this issue..\\

    Thanks & Regards

    Mohan Rajesh Komatlapalli


    Mohan Rajesh Komatlapalli

    Monday, July 14, 2014 11:43 AM

Answers

  • You must convert the Celebrities IEnumerable to an IList by calling the ToList() method on it:

    var Celebrities = from name in CastList
                                   where name.Alphabet != ""
                                   group name by name.Alphabet into c
                                   orderby c.Key
                                   select new Group<CelebrityDetails>(c.Key, c);
                 listCelebrities.ItemsSource = Celebrities.ToList();
    

    Monday, July 14, 2014 3:50 PM

All replies

  • You must convert the Celebrities IEnumerable to an IList by calling the ToList() method on it:

    var Celebrities = from name in CastList
                                   where name.Alphabet != ""
                                   group name by name.Alphabet into c
                                   orderby c.Key
                                   select new Group<CelebrityDetails>(c.Key, c);
                 listCelebrities.ItemsSource = Celebrities.ToList();
    

    Monday, July 14, 2014 3:50 PM
  • Thank Q...  Mr Magnus (MM8)

    It Worked for me...


    Mohan Rajesh Komatlapalli

    Tuesday, July 15, 2014 5:25 AM