当前位置: 首页>>代码示例>>C#>>正文


C# List.ElementAtOrDefault方法代码示例

本文整理汇总了C#中System.Windows.Documents.List.ElementAtOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# List.ElementAtOrDefault方法的具体用法?C# List.ElementAtOrDefault怎么用?C# List.ElementAtOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.List的用法示例。


在下文中一共展示了List.ElementAtOrDefault方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BetterMediaPlayer

        public BetterMediaPlayer(List<Song> songs)
        {
            this.songs = songs;
            currentSongIndex = 0;
            activeSong = songs.ElementAtOrDefault<Song>(currentSongIndex);

            using (MediaLibrary library = new MediaLibrary())
            {
                collectionSongs = library.Songs.ToList();
            }

            MediaPlayer.ActiveSongChanged += (s, e) =>
                {
                    if (MediaPlayer.Queue.ActiveSong == nextSong)
                    {
                        MoveNext();
                    }
                    else if (MediaPlayer.Queue.ActiveSong == prevSong)
                    {
                        MovePrev();
                    }

                };

            MediaPlayer.MediaStateChanged += (s, e) =>
            {
                if (MediaPlayer.State == MediaState.Stopped)
                {
                    MoveNext();
                }

                if (MediaPlayer.State == MediaState.Playing)
                {
                    timer.Change(0, 500);
                }
                else
                {
                    timer.Change(Timeout.Infinite, Timeout.Infinite);
                }
                RaisePropertyChanged(StatePropertyName);
            };

            timer = new Timer(
                x => RaisePropertyChanged(PlayPositionPropertyName),
                null, Timeout.Infinite, Timeout.Infinite);

            // Needed, otherwise our counting logic is completely thrown off
            // because the order is not maintained between the collection passed
            // to MediaPlayer.Play and MediaPlayer.Queue
            MediaPlayer.IsShuffled = false;

            // TODO Ask the user to take over the music
            // TODO Figure out how to clear existing playlist
            MediaPlayer.Stop();

            // TODO Stop music when they quit the app
        }
开发者ID:hamishhill,项目名称:Beat-Machine,代码行数:57,代码来源:BetterMediaPlayer.cs

示例2: PhoneApplicationPage_Loaded

        private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            var fb = new Facebook.FacebookClient(App.AccessToken);
            var result = await fb.GetTaskAsync("fql",
                new
                {
                    //q = "SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 25)"
                    //q = "SELECT aid FROM album WHERE (owner=1383951117)"
                    q = "SELECT src_big,src_small,target_id FROM photo WHERE pid IN (SELECT pid FROM photo_tag WHERE subject='') OR pid IN (SELECT pid FROM photo WHERE aid IN (SELECT aid FROM album WHERE (owner='1383951117') AND type!='profile')) and place_id in (SELECT page_id FROM place WHERE distance(latitude, longitude, '41.878700', '-87.636620') < '50000')"
                });
            //System.Threading.Thread.Sleep(4000);
            System.Diagnostics.Debug.WriteLine("Result: " + result.ToString());
            JObject ob = JObject.Parse(result.ToString());
            JArray data = (JArray)ob["data"];
            int i;
            List<Uri> small=new List<Uri>();       
            List<Uri> big = new List<Uri>();
            for(i=0;i<data.Count;i++)
            {
                JObject a=(JObject)data[i];
                JValue b = (JValue)a["src_big"];
                big.Add(new Uri(b.Value.ToString()));
                b = (JValue)a["src_small"];
                small.Add(new Uri(b.Value.ToString()));
            }

            my_popup_cs.IsOpen = false;

            var GroupedURLs = new List<ImageViewModel>();
            for (int j = 0; j < small.Count; j++)
            {
                var objImageViewModel = new ImageViewModel();
                if (small.ElementAtOrDefault(j) != null)
                {
                    objImageViewModel.First = big[j];
                    objImageViewModel.big = big[j];
                }

                GroupedURLs.Add(objImageViewModel);
            }

            ic.ItemsSource = GroupedURLs;
        }
开发者ID:poojavenkatram,项目名称:hck,代码行数:43,代码来源:LandingPage.xaml.cs

示例3: MainPage

        // Constructor
        public MainPage()
        {
            InitializeComponent();
            var URLs = new List<Uri> 
            {
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative),
                new Uri("/Delhi.png",UriKind.Relative)   
            };

            my_popup_cs.IsOpen = false;

            var GroupedURLs = new List<ImageViewModel>();
            for (int i = 0; i < URLs.Count; i++)
            {
                var objImageViewModel = new ImageViewModel();
                if (URLs.ElementAtOrDefault(i) != null)
                {
                    objImageViewModel.First = URLs[i];
                    objImageViewModel.name = URLs[i].ToString();
                }

                GroupedURLs.Add(objImageViewModel);
            }

            ic.ItemsSource = GroupedURLs;


        }
开发者ID:poojavenkatram,项目名称:hck,代码行数:40,代码来源:MainPage.xaml.cs

示例4: pickThreeQuestions

        // Väljer ut tre frågor till en array från en list som läses in i readQuestion()
        private void pickThreeQuestions(List<string> idList, int antalID, int fraga)
        {
  
            // Om man svarat på tre frågor stängs fönstret.
            if (fraga > 2)
            {
                fraga = 0;
                questAnswered = 0;

                timer.Stop();

                // Några if-satser för att kolla vem som har spelat och vem som inte har, allt för logiken när vi spelar
                if (UserName.spelarNummer == "1")
                {
                    DBconnect.openDB("UPDATE `Match` SET Spelare1Spelat = 1 WHERE MatchID = " + UserName.MatchID);
                    DBconnect.DataReader.Read();
                    DBconnect.DataReader.Close();
                    DBconnect.Connection.Close();
                }

                else // Spelare2
                {
                    DBconnect.openDB("UPDATE `Match` SET Spelare2Spelat = 1 WHERE MatchID = " + UserName.MatchID);
                    DBconnect.DataReader.Read();
                    DBconnect.DataReader.Close();
                    DBconnect.Connection.Close();
                
                }

                DBconnect.openDB("SELECT * FROM `Match` WHERE MatchID = " + UserName.MatchID);
                DBconnect.DataReader.Read();

                // Om båda har spelat denna runda ökar rundan med +1 och att de båda har spelat minskar till 0
                if (Convert.ToString(DBconnect.DataReader["Spelare1Spelat"]) == "1" && Convert.ToString(DBconnect.DataReader["Spelare2Spelat"]) == "1")
                {
                    DBconnect.DataReader.Close();
                    DBconnect.Connection.Close();

                    DBconnect.openDB("UPDATE `Match` SET Runda = Runda+" + 1 + " WHERE MatchID = " + UserName.MatchID + "; " +
                        "UPDATE `Match` SET Spelare1Spelat = 0 WHERE MatchID = " + UserName.MatchID + "; " +
                        "UPDATE `Match` SET Spelare2Spelat = 0 WHERE MatchID = " + UserName.MatchID + ";");
                    DBconnect.DataReader.Read();

                    DBconnect.Connection.Close();
                    DBconnect.DataReader.Close();

                    // Ändrar rating för medlemmen.
                    changeRating();
               
                }

                Switcher.Switch(new Meny());
            }

            // Hämtar ny fråga om man svarat på första frågan.
            else if (fraga > 0)
            {
                setQuestion(arrayFragorRunda[fraga]);
            }

            // Slumpar ut tre frågor från en lista som skapats i readQuestion()
            else
            {
                DBconnect.openDB("SELECT * FROM `Match` WHERE MatchID = " + UserName.MatchID);
                DBconnect.DataReader.Read();

                if (Convert.ToString(DBconnect.DataReader["FragorRunda" + Convert.ToString(DBconnect.DataReader["Runda"])]) != "TOM")
                {
                    DBconnect.DataReader.Close();
                    splitFragor();          
                }
                else if (Convert.ToString(DBconnect.DataReader["FragorRunda" + Convert.ToString(DBconnect.DataReader["Runda"])]) == "TOM")
                {
                    for (int i = 0; i < 3; i++)
                    {
                        Random random = new Random();
                        int num = random.Next(antalID);

                        //Tar FragorID på positionen num
                        idFragaArray[i] = idList.ElementAtOrDefault(num);
                        idList.RemoveAt(num);
                        antalID--;

                    }

                    // Lägger in de utvalda frågorna i databsen till en specifik runda i en specifik match.
                    DBconnect.openDB("UPDATE `Match` SET FragorRunda" + Convert.ToString(DBconnect.DataReader["Runda"]) + " = '" + idFragaArray[0] + "_" + idFragaArray[1] + "_" + idFragaArray[2] + "' WHERE MatchID = " + UserName.MatchID);
                    DBconnect.DataReader.Read();
                    splitFragor();
                }

                DBconnect.DataReader.Close();
                DBconnect.Connection.Close();

                setQuestion(arrayFragorRunda[fraga]);
            }
        }
开发者ID:RATAIT,项目名称:Brainiest,代码行数:98,代码来源:match.xaml.cs


注:本文中的System.Windows.Documents.List.ElementAtOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。