views:

72

answers:

2

Hi,

I have following playlist:

Playlist playList = new Playlist();

I am adding the playList ietms to my playList as 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 suppose my plaList has 9 Items inside it . I want to iterate through each by using foreach loop as following:

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

But I am getting the errror:

foreach statement cannot operate on variables of type 'ExpressionMediaPlayer.Playlist' because 'ExpressionMediaPlayer.Playlist' does not contain a public definition for 'GetEnumerator'

Can any one please explain why this is happening and what is the correct way of doing it.

Thanks, Subhhen

+3  A: 

Probably you have to write:

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

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

Jason
+1  A: 

It seems you want:

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