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


C# System.Collections.Generic.ToList方法代码示例

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


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

示例1: ToVerseWithoutHtml

			public static VerseResponse ToVerseWithoutHtml (string verse, RootObject root)
			{
				var text = root.ResponseData.Search.Result.Passages [0].Text;
				var copyright = root.ResponseData.Search.Result.Passages [0].Copyright;

				var document = new HtmlDocument ();
				document.LoadHtml (text);

				var tags = new [] { "h1", "h2", "h3", "h4", "h5", "h6" };
				List<string> toRemove = tags.ToList ();
				var list = document.DocumentNode.Descendants ()
					.Where (n => toRemove.Contains (n.Name.ToLower ()))
					.ToList ();

				foreach (var item in list) {
					item.Remove ();
				}

				text = document.DocumentNode.InnerText;

				document.LoadHtml (copyright);
				copyright = document.DocumentNode.InnerText;

				return new VerseResponse { Reference = verse, Text = text, Copyright = copyright };
			}
开发者ID:pierceboggan,项目名称:Verses,代码行数:25,代码来源:BiblesDotOrg.cs

示例2: ContainsQueriedData

        public void ContainsQueriedData()
        {
            int n = 20;
            IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n)
                select new TestObj
                {
                    Name = i.ToString()
                };

            var db = new TestDb(new SQLitePlatformWin32(), TestPath.GetTempFileName());

            db.InsertAll(cq);

            db.Trace = true;

            var tensq = new[] {"0", "10", "20"};
            List<TestObj> tens = (from o in db.Table<TestObj>() where tensq.Contains(o.Name) select o).ToList();
            Assert.AreEqual(2, tens.Count);

            var moreq = new[] {"0", "x", "99", "10", "20", "234324"};
            List<TestObj> more = (from o in db.Table<TestObj>() where moreq.Contains(o.Name) select o).ToList();
            Assert.AreEqual(2, more.Count);

            // https://github.com/praeclarum/SQLite.Net/issues/28
            List<string> moreq2 = moreq.ToList();
            List<TestObj> more2 = (from o in db.Table<TestObj>() where moreq2.Contains(o.Name) select o).ToList();
            Assert.AreEqual(2, more2.Count);
        }
开发者ID:giacatlaoboi,项目名称:SQLite.Net-PCL,代码行数:28,代码来源:ContainsTest.cs

示例3: ArrayTests

 public void ArrayTests()
 {
     int[] ints = new[] {0, 1, 2, 3};
     var intList = ints.ToList();
     var expectedResult = new List<int> {0, 1, 2, 3};
     for (int i = 0; i < expectedResult.Count; i++)
     {
         Assert.AreEqual(intList[i], expectedResult[i]);
     }
 }
开发者ID:krishnaglick,项目名称:Senior-Project,代码行数:10,代码来源:UtilityTests.cs

示例4: GivenTwoBlackPairsInStore_WhenGetAllPairs_ThenTwoAreReturned

        public async Task GivenTwoBlackPairsInStore_WhenGetAllPairs_ThenTwoAreReturned()
        {
            var twoPairs = new[] { new SocksPair(SocksColour.Black), new SocksPair(SocksColour.Black), };
            twoPairs.ToList().ForEach(p => Session.Save(p));
            Session.Flush();

            var pairs = (await Client.GetAsync("api/drawer/socks")).BodyAs<IEnumerable<SocksPair>>();

            pairs.Count().ShouldBe(2);
            pairs.ShouldAllBe(p => p.Colour == SocksColour.Black);
        }
开发者ID:cottsak,项目名称:mvc6webapicompare,代码行数:11,代码来源:DrawerControllerTests.cs

示例5: Can_add_aggreate

        public void Can_add_aggreate()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment(), new Comment() };
                var comments1 = new[] { new Comment(), new Comment() };
                var posts = new[] { new Post { Comments = comments0.ToList() }, new Post { Comments = comments1.ToList() } };
                var blog = new Blog { Posts = posts.ToList() };

                context.Add(blog);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:20,代码来源:AggregatesTest.cs

示例6: Can_attach_aggreate

        public void Can_attach_aggreate()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment { Id = 33, PostId = 55 }, new Comment { Id = 34, PostId = 55 } };
                var comments1 = new[] { new Comment { Id = 44, PostId = 56 }, new Comment { Id = 45, PostId = 56 } };
                var posts = new[]
                    {
                        new Post { Id = 55, BlogId = 66, Comments = comments0.ToList() },
                        new Post { Id = 56, BlogId = 66, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[1]).State);
            }
        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:24,代码来源:AggregatesTest.cs

示例7: sort_application_files_last

        public void sort_application_files_last()
        {
            var configs = new[]
            {
                new FubuFile("a.txt", ContentFolder.Application),
                new FubuFile("b.txt", "Pak1"),
                new FubuFile("c.txt", "Pak2")
            };

            SharingConfigActivator.SortConfigsFromApplicationLast(configs.ToList())
                .ShouldHaveTheSameElementsAs(configs[1], configs[2], configs[0]);
        }
开发者ID:hartez,项目名称:FubuMVC.ViewEngines,代码行数:12,代码来源:SharingConfigActivatorTester.cs

示例8: Attaching_aggregate_with_no_key_set_adds_it_instead

        public void Attaching_aggregate_with_no_key_set_adds_it_instead()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment(), new Comment() };
                var comments1 = new[] { new Comment(), new Comment() };
                var posts = new[] { new Post { Comments = comments0.ToList() }, new Post { Comments = comments1.ToList() } };
                var blog = new Blog { Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:20,代码来源:AggregatesTest.cs

示例9: Can_add_two_aggregates_linked_down_the_tree

        public void Can_add_two_aggregates_linked_down_the_tree()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder { Id = 11 }, new Reminder { Id = 12 } };
                var author = new Author { Id = 22, Reminders = reminders.ToList() };

                var comments0 = new[] { new Comment { Id = 33, Author = author }, new Comment { Id = 34, Author = author } };
                var comments1 = new[] { new Comment { Id = 44, Author = author }, new Comment { Id = 45, Author = author } };
                var posts = new[]
                    {
                        new Post { Id = 55, Author = author, Comments = comments0.ToList() },
                        new Post { Id = 56, Author = author, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Author = author, Posts = posts.ToList() };

                context.AddRange(blog, author);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(author).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[1]).State);
            }
        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:30,代码来源:AggregatesTest.cs

示例10: Can_attach_aggregate_with_linked_aggregate_not_attached

        public void Can_attach_aggregate_with_linked_aggregate_not_attached()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder { Id = 11 }, new Reminder { Id = 12 } };
                var author = new Author { Id = 22, Reminders = reminders.ToList() };

                var comments0 = new[] { new Comment { Id = 33, Author = author }, new Comment { Id = 34, Author = author } };
                var comments1 = new[] { new Comment { Id = 44, Author = author }, new Comment { Id = 45, Author = author } };
                var posts = new[]
                    {
                        new Post { Id = 55, Author = author, Comments = comments0.ToList() },
                        new Post { Id = 56, Author = author, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Author = author, Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Detached, context.Entry(author).State);
                Assert.Equal(EntityState.Detached, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Detached, context.Entry(reminders[1]).State);
            }
        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:30,代码来源:AggregatesTest.cs

示例11: Dependents_with_no_key_set_are_added

        public void Dependents_with_no_key_set_are_added()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment { Id = 33, PostId = 55 }, new Comment { Id = 34, PostId = 55 } };
                var comments1 = new[] { new Comment { PostId = 56 }, new Comment { PostId = 56 } };
                var posts = new[]
                    {
                        new Post { Id = 55, BlogId = 66, Comments = comments0.ToList() },
                        new Post { BlogId = 66, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
开发者ID:adwardliu,项目名称:EntityFramework,代码行数:24,代码来源:AggregatesTest.cs

示例12: GivenOneBlackAndSixWhiteSocks_WhenPostWhite_ThenFailWithForbidden

        public async Task GivenOneBlackAndSixWhiteSocks_WhenPostWhite_ThenFailWithForbidden()
        {
            var allPairsInStore = new[]
                {
                    new SocksPair(SocksColour.Black),
                    new SocksPair(SocksColour.White),
                    new SocksPair(SocksColour.White),
                    new SocksPair(SocksColour.White),
                    new SocksPair(SocksColour.White),
                    new SocksPair(SocksColour.White),
                    new SocksPair(SocksColour.White),
                };
            allPairsInStore.ToList().ForEach(p => Session.Save(p));
            Session.Flush();

            var response = await Client.PostJsonAsync("api/drawer", new { colour = "white" });

            response.StatusCode.ShouldBe(HttpStatusCode.Forbidden);
            response.BodyAs<string>().ShouldContain("6");
        }
开发者ID:cottsak,项目名称:mvc6webapicompare,代码行数:20,代码来源:DrawerControllerTests.cs

示例13: test

        private void test()
        {
            var list = new SkipList();
            var toInsert = new[] { 7, 2, 9, 1, 10 };
            foreach (var value in toInsert)
            {
                list.Insert(value);
            }

            // test whether the elements were inserted
            var listValues = list.GetElements();
            var sortedList = toInsert.ToList();
            sortedList.Sort();
            Assert.That(listValues.ToList(), Is.EquivalentTo(sortedList));

            list.PrintConfiguration();

            // test the existence of different values
            var mapExistence = new Dictionary<int, bool>
                          {
                              { 0, false },
                              { 1, true },
                              { 2, true },
                              { 3, false },
                              { 4, false },
                              { 5, false },
                              { 6, false },
                              { 7, true },
                              { 8, false },
                              { 9, true },
                              { 10, true }
                          };
            foreach (var pair in mapExistence)
            {
                Assert.AreEqual(list.Exists(pair.Key), pair.Value);
            }

            // find closest elementvar mapExistence = new Dictionary<int, bool>
            var mapClosest = new Dictionary<int, int>
                          {
                              { 0, 1 },
                              { 1, 1 },
                              { 2, 2 },
                              { 3, 2 },
                              { 4, 2 },
                              { 5, 7 },
                              { 6, 7 },
                              { 7, 7 },
                              { 8, 7 },
                              { 9, 9 },
                              { 10, 10 }
                          };
            foreach (var pair in mapClosest)
            {
                Assert.AreEqual(list.FindClosestElement(pair.Key), pair.Value);
            }

            // find k-th largest element
            var mapKth = new Dictionary<int, int?>
                          {
                              { 1, 1 },
                              { 2, 2 },
                              { 3, 7 },
                              { 4, 9 },
                              { 5, 10 }
                          };
            foreach (var pair in mapKth)
            {
                Assert.AreEqual(list.FindKLargestElement(pair.Key), pair.Value);
            }

            // count elements in range
            var rangeList = new List<dynamic>
                {
                    new
                        {
                            Left = 0,
                            Right = 11,
                            Count = 5
                        },
                    new
                        {
                            Left = 1,
                            Right = 10,
                            Count = 5
                        },
                    new
                        {
                            Left = 2,
                            Right = 10,
                            Count = 4
                        },
                    new
                        {
                            Left = 3,
                            Right = 10,
                            Count = 3
                        },
                    new
                        {
//.........这里部分代码省略.........
开发者ID:htoma,项目名称:algorithms,代码行数:101,代码来源:SkipListsTests.cs

示例14: ToVerseTextWithoutHtml

			public static string ToVerseTextWithoutHtml (RootObject root)
			{
				var text = root.ResponseData.Search.Result.Passages [0].Text;
				var document = new HtmlDocument();
				document.LoadHtml (text);

				var tags = new [] { "h1", "h2", "h3", "h4", "h5", "h6" };
				List<string> toRemove = tags.ToList ();
				var list = document.DocumentNode.Descendants ()
					.Where (n => toRemove.Contains (n.Name.ToLower ()))
					.ToList ();

				foreach (var item in list) {
					item.Remove ();
				}

				return document.DocumentNode.InnerText.Replace ("\n", " ").Replace ("\r", " ");
			}
开发者ID:pierceboggan,项目名称:Verses,代码行数:18,代码来源:BiblesDotOrg.cs

示例15: Can_add_aggregate_with_other_linked_aggregate_also_attached

        public void Can_add_aggregate_with_other_linked_aggregate_also_attached()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder { Id = 11 }, new Reminder { Id = 12 } };
                var author = new Author { Id = 22, Reminders = reminders.ToList() };

                var comments0 = new[] { new Comment { Id = 33, Author = author }, new Comment { Id = 34, Author = author } };
                var comments1 = new[] { new Comment { Id = 44, Author = author }, new Comment { Id = 45, Author = author } };
                var posts = new[]
                {
                    new Post { Id = 55, Author = author, Comments = comments0.ToList() },
                    new Post { Id = 56, Author = author, Comments = comments1.ToList() }
                };
                var blog = new Blog { Id = 66, Author = author, Posts = posts.ToList() };

                author.Comments = comments0.Concat(comments1).ToList();
                comments0[0].Post = posts[0];
                posts[0].Blog = blog;

                context.Add(author);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(author).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[1]).State);
            }
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:34,代码来源:AggregatesTest.cs


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