How to iterate over a playlist using foreachLoop?

I have the following playlist:

Playlist playList = new Playlist();

      

I am adding ietms playList to my playlist as shown below:

if (strmediaExtension == "wmv" || strmediaExtension == "mp4" || strmediaExtension == "mp3" || strmediaExtension == "mpg")
                {
                    PlaylistItem playListItem = new PlaylistItem();
                    string thumbSource = folderItems.strAlbumcoverImage;
                    playListItem.MediaSource = new Uri(strmediaURL, UriKind.RelativeOrAbsolute);

                    playListItem.Title = folderItems.strAlbumName;

                    if (!string.IsNullOrEmpty(thumbSource))
                        playListItem.ThumbSource = new Uri(thumbSource, UriKind.RelativeOrAbsolute);

                    playList.Items.Add(playListItem);
                }

      

Now let's say my plaList has 9 elements inside it. I want to iterate over each one using a loop foreach

like this:

foreach (PlaylistItem p in playList)
                    { 
                    //Code Goes here
                    }

      

But I am getting the error:

foreach statement cannot work with variables of type "ExpressionMediaPlayer.Playlist" because "ExpressionMediaPlayer.Playlist" does not have a public definition for "GetEnumerator"

Can someone please explain why this is happening and what is the correct way of it.

Thanks, Subhhen

+2


a source to share


2 answers


Perhaps you need to write:

foreach (PlaylistItem p in playList.Items)
{ 
  //Code Goes here
}

      



More information using foreach: http://msdn.microsoft.com/en-us/library/aa288257(VS.71).aspx

+5


a source


You seem to want:



foreach(PlaylistItem p in playList.Items)
{
    //code goes here
}

      

+1


a source







All Articles