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


C# System.Slice方法代码示例

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


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

示例1: Slice

 public void Slice()
 {
     var array = new[] { 1, 2, 3 };
     var slice = array.Slice(1, 0);
     Assert.AreEqual(0, slice.Length);
     slice = array.Slice(0, 3);
     CollectionAssert.AreEqual(array, slice);
     slice = array.Slice(1, 2);
     Assert.AreEqual(2, slice.Length);
     Assert.AreEqual(2, slice[0]);
     Assert.AreEqual(3, slice[1]);
 }
开发者ID:GordenOu,项目名称:Core.Extensions,代码行数:12,代码来源:ArrayExtensionsTests.cs

示例2: SliceTestCase1ArgumentOutOfRangeException

        public void SliceTestCase1ArgumentOutOfRangeException()
        {
            var sourceArray = new[]
            {
                1
            };
            var targetArray = new Int32[2];

            Action test = () => sourceArray.Slice( 2, targetArray );

            test.ShouldThrow<ArgumentOutOfRangeException>();
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:12,代码来源:Array.Generic.Slice.Test.cs

示例3: SliceTestCase

        public void SliceTestCase()
        {
            var sourceArray = new[]
            {
                1,
                2,
                3,
                4
            };

            var actual = sourceArray.Slice( 2 );

            Assert.AreEqual( 2, actual.Length );
            Assert.AreEqual( 1, actual[0] );
            Assert.AreEqual( 2, actual[1] );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:16,代码来源:Array.Generic.Slice.Test.cs

示例4: SliceTestCase1

        public void SliceTestCase1()
        {
            var sourceArray = new[]
            {
                1,
                2,
                3,
                4
            };
            var targetArray = new Int32[2];

            var actual = sourceArray.Slice( 2, targetArray );

            Assert.AreSame( targetArray, actual );
            Assert.AreEqual( 2, actual.Length );
            Assert.AreEqual( 1, actual[0] );
            Assert.AreEqual( 2, actual[1] );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:18,代码来源:Array.Generic.Slice.Test.cs

示例5: AddCornerAdorner

		private void AddCornerAdorner(ICollection<LLShape> list, PointT point, VectorT vector)
		{
			VectorT up = new VectorT(0, -vector.Y), down = new VectorT(0, vector.Y);
			VectorT left = new VectorT(-vector.X, 0), right = new VectorT(vector.X, 0);
			var points = new[] { 
				point, point.Add(up), point.Add(up).Add(right), 
				point.Add(vector), point.Add(left).Add(down), point.Add(left)
			};
			list.Add(new LLPolygon(SelAdornerFillStyle, points));
			list.Add(new LLPolyline(SelAdornerLineStyle, points.Slice(1).AsList()));
		}
开发者ID:jonathanvdc,项目名称:Loyc,代码行数:11,代码来源:TextBox.cs

示例6: SliceTestCaseArgumentOutOfRangeExceptio

        public void SliceTestCaseArgumentOutOfRangeExceptio()
        {
            var sourceArray = new[]
            {
                1,
                2,
                3,
                4
            };

            Action test = () => sourceArray.Slice( 10 );

            test.ShouldThrow<ArgumentOutOfRangeException>();
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:14,代码来源:Array.Generic.Slice.Test.cs

示例7: ListExtensions_Partition_Slice_EndIndexTooSmall

        public void ListExtensions_Partition_Slice_EndIndexTooSmall()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            Assert.Throws<IndexOutOfRangeException>(() => ls.Slice(0, -100000));
        }
开发者ID:konkked,项目名称:Underscore.cs,代码行数:6,代码来源:PartitionTest.cs

示例8: ListExtensions_Partition_LargeLists

        public void ListExtensions_Partition_LargeLists()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            var slice = ls.Slice(0, 1000, true);

            Assert.AreEqual(slice.Count, 1000);

            slice = ls.Slice(0, 10000, true);
            Assert.AreEqual(slice.Count, 10000);

            slice = ls.Slice(0, 100000, true);
            Assert.AreEqual(slice.Count, 100000);

            slice = ls.Slice(0, -1000000, true);
            Assert.AreEqual(slice.Count, 1000000);
        }
开发者ID:konkked,项目名称:Underscore.cs,代码行数:17,代码来源:PartitionTest.cs

示例9: ListExtensions_Partition_NegativeBackwardsOverflowWithPositiveStep

        public void ListExtensions_Partition_NegativeBackwardsOverflowWithPositiveStep()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // slice length > list length
            // negative backwards
            Assert.Throws<InvalidOperationException>(() => ls.Slice(2, -13, 2, true));
        }
开发者ID:konkked,项目名称:Underscore.cs,代码行数:8,代码来源:PartitionTest.cs

示例10: ListExtensions_Parition_Slice_SingleItem

        public void ListExtensions_Parition_Slice_SingleItem()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            //slice of one
            Assert.IsTrue(ls.Slice(0, 1).SequenceEqual(new[] { 0 }));
        }
开发者ID:konkked,项目名称:Underscore.cs,代码行数:7,代码来源:PartitionTest.cs

示例11: ListExtensions_Partition_SlicePostiveForwardWithNegativeStepException

        public void ListExtensions_Partition_SlicePostiveForwardWithNegativeStepException()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // slice length < list length 
            // positive 
            // forward 
            // this should throw an exception
            Assert.Throws<InvalidOperationException>(() => ls.Slice(0, 8, -2));
        }
开发者ID:konkked,项目名称:Underscore.cs,代码行数:10,代码来源:PartitionTest.cs

示例12: ListExtensions_Partition_SlicePostiveForwardWithPositiveStep

        public void ListExtensions_Partition_SlicePostiveForwardWithPositiveStep()
        {
            var ls = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // slice length < list length 
            // positive 
            // forward 
            var slice = ls.Slice(0, 8, 2);

            // result should be 0 , 2 , 4 , 6
            Assert.IsTrue(slice.SequenceEqual(new[] { 0, 2, 4, 6 }));
        }
开发者ID:konkked,项目名称:Underscore.cs,代码行数:12,代码来源:PartitionTest.cs

示例13: Test_Matrix_Slicing_With_Indices

        public void Test_Matrix_Slicing_With_Indices()
        {
            Matrix x = new[,]{
                { 0d, 10 },
                { 1d, 20 },
                { 2d, 30 },
                { 3d, 40 },
                { 4d, 50 },
                { 5d, 60 },
                { 6d, 70 },
            };

            var indices = new[] { 6, 4, 2, 4, 1 };

            Matrix truth = new[,]{
                { 1d, 20 },
                { 2d, 30 },
                { 4d, 50 },
                { 6d, 70 },
            };

            var actual = x.Slice(indices);

            Assert.AreEqual(truth, actual);
        }
开发者ID:m-abubakar,项目名称:numl,代码行数:25,代码来源:HelperTests.cs

示例14: TestSubslice

    public bool TestSubslice(Tester t)
    {
        var slice = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }.Slice();

        // First a simple subslice over the whole array, using start.
        {
            var subslice1 = slice.Slice(0);
            t.AssertEqual(slice.Length, subslice1.Length);
            for (int i = 0; i < slice.Length; i++) {
                t.AssertEqual(slice[i], subslice1[i]);
            }
        }

        // Next a simple subslice over the whole array, using start and end.
        {
            var subslice2 = slice.Slice(0, slice.Length);
            t.AssertEqual(slice.Length, subslice2.Length);
            for (int i = 0; i < slice.Length; i++) {
                t.AssertEqual(slice[i], subslice2[i]);
            }
        }

        // Now do something more interesting; just take half the array.
        {
            int mid = slice.Length/2;
            var subslice3 = slice.Slice(mid);
            t.AssertEqual(mid, subslice3.Length);
            for (int i = mid, j = 0; i < slice.Length; i++, j++) {
                t.AssertEqual(slice[i], subslice3[j]);
            }
        }

        // Now take a hunk out of the middle.
        {
            int st = 3;
            int ed = 7;
            var subslice4 = slice.Slice(st, ed);
            t.AssertEqual(ed-st, subslice4.Length);
            for (int i = ed, j = 0; i < ed; i++, j++) {
                t.AssertEqual(slice[i], subslice4[j]);
            }
        }

        return true;
    }
开发者ID:IDisposable,项目名称:corefxlab,代码行数:45,代码来源:Tests.cs

示例15: ArrayExtensions_Slice

        public void ArrayExtensions_Slice()
        {
            var inner = new[] { 1, 2, 3, 4, 5 };

            var subject = inner.Slice(0, 5);
            Check.That(subject.Start).IsEqualTo(0);
            Check.That(subject.Length).IsEqualTo(5);
        }
开发者ID:akatakritos,项目名称:PygmentSharp,代码行数:8,代码来源:SliceTests.cs


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