本文整理汇总了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]);
}
示例2: SliceTestCase1ArgumentOutOfRangeException
public void SliceTestCase1ArgumentOutOfRangeException()
{
var sourceArray = new[]
{
1
};
var targetArray = new Int32[2];
Action test = () => sourceArray.Slice( 2, targetArray );
test.ShouldThrow<ArgumentOutOfRangeException>();
}
示例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] );
}
示例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] );
}
示例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()));
}
示例6: SliceTestCaseArgumentOutOfRangeExceptio
public void SliceTestCaseArgumentOutOfRangeExceptio()
{
var sourceArray = new[]
{
1,
2,
3,
4
};
Action test = () => sourceArray.Slice( 10 );
test.ShouldThrow<ArgumentOutOfRangeException>();
}
示例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));
}
示例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);
}
示例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));
}
示例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 }));
}
示例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));
}
示例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 }));
}
示例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);
}
示例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;
}
示例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);
}