本文整理汇总了C#中Playlist.AddSong方法的典型用法代码示例。如果您正苦于以下问题:C# Playlist.AddSong方法的具体用法?C# Playlist.AddSong怎么用?C# Playlist.AddSong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Playlist
的用法示例。
在下文中一共展示了Playlist.AddSong方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: initWithStartingSong
private void initWithStartingSong(Track t)
{
int trackIndex = unshuffledPlaylist.Songs.IndexOf(t);
unrepeatedPlaylistLength = unshuffledPlaylist.Count();
currentIndex = 0;
//create and initialize array with number of elements equal to items in the playlist
int[] shuffledPlaylistIndexes = new int[unrepeatedPlaylistLength];
shuffledPlaylistIndexes[0] = trackIndex;
for (int counter = 1; counter < unrepeatedPlaylistLength; counter++)
{
if (counter != trackIndex)
shuffledPlaylistIndexes[counter] = counter;
}
// To shuffle an array a of n elements (indices 0..n-1):
for (int i = unrepeatedPlaylistLength - 1; i >= 1; i--)
{
Random r = new Random();
int j = r.Next(1, i);
int num1 = shuffledPlaylistIndexes[j];
int num2 = shuffledPlaylistIndexes[i];
shuffledPlaylistIndexes[j] = num2;
shuffledPlaylistIndexes[i] = num1;
}
shuffledPlaylist = new Playlist();
for (int counter = 0; counter < shuffledPlaylistIndexes.Length; counter++)
shuffledPlaylist.AddSong(unshuffledPlaylist.ElementAt(shuffledPlaylistIndexes[counter]));
}
示例2: init
private void init()
{
unrepeatedPlaylistLength = unshuffledPlaylist.Count();
currentIndex = -1;
//create and initialize array with number of elements equal to items in the playlist
int[] shuffledPlaylistIndexes = new int[unrepeatedPlaylistLength];
for (int counter = 0; counter < unrepeatedPlaylistLength; counter++)
shuffledPlaylistIndexes[counter] = counter;
// To shuffle an array a of n elements (indices 0..n-1):
for (int i = unrepeatedPlaylistLength - 1; i >= 0; i--)
{
Random r = new Random();
int j = r.Next(0, i);
int num1 = shuffledPlaylistIndexes[j];
int num2 = shuffledPlaylistIndexes[i];
shuffledPlaylistIndexes[j] = num2;
shuffledPlaylistIndexes[i] = num1;
}
shuffledPlaylist = new Playlist();
for (int counter = 0; counter < shuffledPlaylistIndexes.Length; counter++)
shuffledPlaylist.AddSong(unshuffledPlaylist.ElementAt(shuffledPlaylistIndexes[counter]));
}