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


C# System.Collections.Skip方法代码示例

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


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

示例1: Select_SourceIsArray_First

        public void Select_SourceIsArray_First()
        {
            var source = new[] { 1, 2, 3, 4 }.Select(i => i * 2);
            Assert.Equal(2, source.First());
            Assert.Equal(2, source.FirstOrDefault());

            Assert.Equal(6, source.Skip(2).First());
            Assert.Equal(6, source.Skip(2).FirstOrDefault());
            Assert.Throws<InvalidOperationException>(() => source.Skip(4).First());
            Assert.Throws<InvalidOperationException>(() => source.Skip(14).First());
            Assert.Equal(0, source.Skip(4).FirstOrDefault());
            Assert.Equal(0, source.Skip(14).FirstOrDefault());

            var empty = new int[0].Select(i => i * 2);
            Assert.Throws<InvalidOperationException>(() => empty.First());
            Assert.Equal(0, empty.FirstOrDefault());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:17,代码来源:SelectTests.cs

示例2: Select_SourceIsArray_ElementAtOrDefault

        public void Select_SourceIsArray_ElementAtOrDefault()
        {
            var source = new[] { 1, 2, 3, 4 }.Select(i => i * 2);
            for (int i = 0; i != 4; ++i)
                Assert.Equal(i * 2 + 2, source.ElementAtOrDefault(i));
            Assert.Equal(0, source.ElementAtOrDefault(-1));
            Assert.Equal(0, source.ElementAtOrDefault(4));
            Assert.Equal(0, source.ElementAtOrDefault(40));

            Assert.Equal(6, source.Skip(1).ElementAtOrDefault(1));
            Assert.Equal(0, source.Skip(2).ElementAtOrDefault(9));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:SelectTests.cs

示例3: Select_SourceIsArray_Take

 public void Select_SourceIsArray_Take()
 {
     var source = new[] { 1, 2, 3, 4 }.Select(i => i * 2);
     Assert.Equal(new[] { 2, 4 }, source.Take(2));
     Assert.Equal(new[] { 2, 4 }, source.Take(3).Take(2));
     Assert.Empty(source.Take(-1));
     Assert.Equal(new[] { 2, 4, 6, 8 }, source.Take(4));
     Assert.Equal(new[] { 2, 4, 6, 8 }, source.Take(40));
     Assert.Equal(new[] { 2 }, source.Take(1));
     Assert.Equal(new[] { 4 }, source.Skip(1).Take(1));
     Assert.Equal(new[] { 6 }, source.Take(3).Skip(2));
     Assert.Equal(new[] { 2 }, source.Take(3).Take(1));
 }
开发者ID:dotnet,项目名称:corefx,代码行数:13,代码来源:SelectTests.cs

示例4: Select_SourceIsArray_ElementAt

        public void Select_SourceIsArray_ElementAt()
        {
            var source = new[] { 1, 2, 3, 4 }.Select(i => i * 2);
            for (int i = 0; i != 4; ++i)
                Assert.Equal(i * 2 + 2, source.ElementAt(i));
            Assert.Throws<ArgumentOutOfRangeException>("index", () => source.ElementAt(-1));
            Assert.Throws<ArgumentOutOfRangeException>("index", () => source.ElementAt(4));
            Assert.Throws<ArgumentOutOfRangeException>("index", () => source.ElementAt(40));

            Assert.Equal(6, source.Skip(1).ElementAt(1));
            Assert.Throws<ArgumentOutOfRangeException>("index", () => source.Skip(2).ElementAt(9));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:SelectTests.cs

示例5: Select_SourceIsArray_Skip

 public void Select_SourceIsArray_Skip()
 {
     var source = new[] { 1, 2, 3, 4 }.Select(i => i * 2);
     Assert.Equal(new[] { 6, 8 }, source.Skip(2));
     Assert.Equal(new[] { 6, 8 }, source.Skip(2).Skip(-1));
     Assert.Equal(new[] { 6, 8 }, source.Skip(1).Skip(1));
     Assert.Equal(new[] { 2, 4, 6, 8 }, source.Skip(-1));
     Assert.Empty(source.Skip(4));
     Assert.Empty(source.Skip(20));
 }
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:SelectTests.cs


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