开发者

How to iterate through Playlist using foreachLoop?

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开发者_Python百科 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


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


It seems you want:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜