コード例 #1
0
        public void TestingOurOwnIEnumerable()
        {
            var stops = new Stops();


            foreach (var stop in stops)
            {
                Console.WriteLine(stop);
            }

            var results = stops.Where(x => x.StopID > 3);
        }
コード例 #2
0
        public void IEnumerableAsReturnValue()
        {
            // fyi, constructor populates collection with some stops
            Stops stops = new Stops();

            // linq returns IEnumerable
            IEnumerable <Stop> results = stops.Where(s => s.StopID > 2);

            // verify that the IEnumerable results IS a reference to stops
            foreach (var result in results)
            {
                result.StopID = 100;
            }

            foreach (var stop in stops)
            {
                Console.WriteLine(stop);
            }

            // unless .ToList() is used
            Stops stops2 = new Stops();
            IEnumerable <Stop> results2 = stops.Where(s => s.StopID > 2).ToList();
        }
コード例 #3
0
        public TrailViewModel(Trail trail)
        {
            this.trail = trail;
            LoadTrailStopAsync();

            ItemTappedCommand = new Command((obj) =>
            {
                StopViewModel stop = obj as StopViewModel;

                var stopViews = Stops
                                .Where(d => d.StopID == stop.StopID)
                                .Select(d => d)
                                .Single();
                var mainPage  = App.Current.MainPage;
                var navgation = mainPage.Navigation;
                navgation.PushAsync(new Views.StopPage(stopViews));
            });
        }
コード例 #4
0
        public void TestDoesAlteringResultChangeOriginalSequence()
        {
            var stops = new Stops();

            // OrderBy does not alter the original list
            var sorted = stops.OrderByDescending(s => s.StopID);

            sorted.ElementAt(0).StopID = 88;

            var result = stops.Where(x => x.StopID % 2 == 0);

            foreach (var evenStop in result)
            {
                evenStop.StopID = 99;
            }

            foreach (var stop in stops)
            {
                Debug.WriteLine(stop);
            }
        }
コード例 #5
0
 public void TestSimpleLambdaWithIEnumerable()
 {
     Stops stops  = new Stops();
     var   result = stops.Where(x => x.StopID > 3);
 }