本文整理汇总了C#中RubyArray.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# RubyArray.RemoveAt方法的具体用法?C# RubyArray.RemoveAt怎么用?C# RubyArray.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RubyArray
的用法示例。
在下文中一共展示了RubyArray.RemoveAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RubyArray_Ctors
public void RubyArray_Ctors() {
const int N = 10;
var dict = new Dictionary<object, object>();
for (int i = 0; i < N; i++) {
dict.Add(i, i);
}
RubyArray a;
a = RubyArray.Create(1);
Assert(a.Count == 1 && (int)a[0] == 1);
a = new RubyArray();
Assert(a.Count == 0 && a.Capacity == 0);
a = new RubyArray(1);
Assert(a.Count == 0 && a.Capacity == Utils.MinListSize);
a = new RubyArray(100);
Assert(a.Count == 0 && a.Capacity == 100);
a = new RubyArray((ICollection)dict.Values);
Assert(a.Count == N);
a = new RubyArray((IEnumerable)dict.Values);
Assert(a.Count == N);
a = new RubyArray((IList)new object[] { 1, 2, 3 });
Assert(a.Count == 3);
Assert((int)a[0] == 1 && (int)a[1] == 2 && (int)a[2] == 3);
a = new RubyArray((IList)new object[] { 1, 2, 3 }, 1, 1);
Assert(a.Count == 1);
Assert((int)a[0] == 2);
a = new RubyArray((IList)new object[] { 1, 2, 3 }, 1, 0);
Assert(a.Count == 0);
a = new RubyArray((ICollection)new object[] { 1, 2, 3 });
Assert(a.Count == 3);
Assert((int)a[0] == 1 && (int)a[1] == 2 && (int)a[2] == 3);
a = new RubyArray((IEnumerable)new object[] { 1, 2, 3 });
Assert(a.Count == 3);
Assert((int)a[0] == 1 && (int)a[1] == 2 && (int)a[2] == 3);
a = new RubyArray(Enumerable(3));
Assert(a.Count == 3);
Assert((int)a[0] == 1 && (int)a[1] == 2 && (int)a[2] == 3);
a = new RubyArray(a);
Assert(a.Count == 3);
Assert((int)a[0] == 1 && (int)a[1] == 2 && (int)a[2] == 3);
a = new RubyArray(a, 0, 2);
Assert(a.Count == 2);
Assert((int)a[0] == 1 && (int)a[1] == 2);
// prepare array [nil, 1, 3, nil]
RubyArray b = new RubyArray(new[] { 1, 2, 3 });
b.RemoveAt(1);
a = new RubyArray(b);
Assert(a.Count == 2);
Assert((int)a[0] == 1 && (int)a[1] == 3);
a = new RubyArray(b, 2, 0);
Assert(a.Count == 0);
a = new RubyArray();
a.AddRange(b);
Assert(a.Count == 2);
Assert((int)a[0] == 1 && (int)a[1] == 3);
a = new RubyArray();
a.AddRange(b, 1, 1);
Assert(a.Count == 1);
Assert((int)a[0] == 3);
a = new RubyArray(new[] { 1, 2, 3 });
AssertExceptionThrown<ArgumentNullException>(() => new RubyArray(null, 1, 2));
AssertExceptionThrown<ArgumentOutOfRangeException>(() => new RubyArray(a, -1, 2));
AssertExceptionThrown<ArgumentOutOfRangeException>(() => new RubyArray(a, 3, 1));
AssertExceptionThrown<ArgumentOutOfRangeException>(() => new RubyArray(a, 0, 4));
}
示例2: RubyArray_Remove
public void RubyArray_Remove() {
RubyArray a;
a = new RubyArray(new[] { 1, 2, 3, 4, 5 });
a.RemoveAt(1);
AssertValueEquals(a, 1, 3, 4, 5);
a.RemoveAt(1);
AssertValueEquals(a, 1, 4, 5);
a.RemoveAt(1);
AssertValueEquals(a, 1, 5);
a.RemoveAt(1);
AssertValueEquals(a, 1);
a.AddRange(new[] { 2, 3 });
AssertValueEquals(a, 1, 2, 3);
a.RemoveAt(0);
AssertValueEquals(a, 2, 3);
a.RemoveAt(0);
AssertValueEquals(a, 3);
a.RemoveAt(0);
AssertValueEquals(a);
a.AddRange(new[] { 1, 2, 3 });
AssertValueEquals(a, 1, 2, 3);
a = new RubyArray();
a.AddMultiple(100, 1);
a[0] = 0;
a[99] = 99;
a.RemoveRange(1, 98);
AssertValueEquals(a, 0, 99);
Assert(a.Capacity < 100, "array should shrink");
((IList)a).Remove(0);
AssertValueEquals(a, 99);
a.Clear();
Assert(a.Count == 0);
a = new RubyArray(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 });
a.RemoveRange(0, 4);
AssertValueEquals(a, 4, 5, 6, 7, 8, 9, 10, 11);
a.AddMultiple(3, 1);
AssertValueEquals(a, 4, 5, 6, 7, 8, 9, 10, 11, 1, 1, 1);
a.RemoveRange(0, 6);
AssertValueEquals(a, 10, 11, 1, 1, 1);
a.AddMultiple(2, 2);
AssertValueEquals(a, 10, 11, 1, 1, 1, 2, 2);
a = new RubyArray();
a = new RubyArray(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 });
a.RemoveRange(0, 4);
AssertValueEquals(a, 4, 5, 6, 7, 8, 9, 10, 11);
a.AddMultiple(3, null);
AssertValueEquals(a, 4, 5, 6, 7, 8, 9, 10, 11, null, null, null);
var vector = new object[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
a = new RubyArray(vector);
for (int i = 0, c = a.Count; i < c; i++) {
a.RemoveAt(0);
vector = ArrayUtils.ShiftLeft(vector, 1);
AssertValueEquals(a, vector);
}
a = new RubyArray(new[] { 1, 2, 3 });
a.Freeze();
Assert(!a.Remove(0));
AssertExceptionThrown<RuntimeError>(() => a.Remove(1));
AssertExceptionThrown<RuntimeError>(() => a.Clear());
AssertExceptionThrown<RuntimeError>(() => a.RemoveAt(0));
AssertExceptionThrown<RuntimeError>(() => a.RemoveRange(0, 1));
}