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


C# RubyArray.Insert方法代码示例

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


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

示例1: RubyArray_Insert

        public void RubyArray_Insert() {
            RubyArray a;
            a = new RubyArray(new[] { 1, 2, 3, 4, 5 });
            a.InsertRange(0, new[] { 10, 20, 30, 40 });
            AssertValueEquals(a, 10, 20, 30, 40, 1, 2, 3, 4, 5);
            a.InsertRange(2, new[] { 8 });
            AssertValueEquals(a,10, 20, 8, 30, 40, 1, 2, 3, 4, 5);
            a.InsertRange(10, new[] { 9 });
            AssertValueEquals(a, 10, 20, 8, 30, 40, 1, 2, 3, 4, 5, 9);

            a.RemoveRange(1, 5);
            AssertValueEquals(a, 10, 2, 3, 4, 5, 9);
            a.InsertRange(1, new[] { 0 });
            AssertValueEquals(a, 10, 0, 2, 3, 4, 5, 9);
            a.InsertRange(6, new[] { 8 });
            AssertValueEquals(a, 10, 0, 2, 3, 4, 5, 8, 9);
            a.RemoveRange(6, 2);
            AssertValueEquals(a, 10, 0, 2, 3, 4, 5);
            a.InsertRange(3, new[] { 11, 12, 13, 14 });
            AssertValueEquals(a, 10, 0, 2, 11, 12, 13, 14, 3, 4, 5);

            a = new RubyArray(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

            // make enough space on both sides:
            a.RemoveRange(0, 2);
            AssertValueEquals(a, 2, 3, 4, 5, 6, 7, 8, 9);
            a.RemoveRange(6, 2);
            AssertValueEquals(a, 2, 3, 4, 5, 6, 7);

            // closer to start:
            a.InsertRange(1, new[] { 10 });
            AssertValueEquals(a, 2, 10, 3, 4, 5, 6, 7);

            // closer to end:
            a.InsertRange(5, new[] { 11 });
            AssertValueEquals(a, 2, 10, 3, 4, 5, 11, 6, 7);

            a = new RubyArray(new[] { 1, 2, 3 });
            a.Insert(0, 0);
            AssertValueEquals(a, 0, 1, 2, 3);
            a.InsertRange(0, Enumerable(2));
            AssertValueEquals(a, 1, 2, 0, 1, 2, 3);
            a.InsertRange(0, new RubyArray(new[] { 1, 0 }), 1, 1);
            a.InsertRange(0, new object[] { 0, -1 }, 1, 1);
            a.InsertRange(0, new[] { 0, -2 }, 1, 1);
            AssertValueEquals(a, -2, -1, 0, 1, 2, 0, 1, 2, 3);
            a.InsertRange(0, (IEnumerable)new RubyArray(new[] { 30 }));
            a.InsertRange(0, (IEnumerable)new object[] { 20 });
            a.InsertRange(0, (IEnumerable)new[] { 10 });
            AssertValueEquals(a, 10, 20, 30, -2, -1, 0, 1, 2, 0, 1, 2, 3);
            
            a.Freeze();
            AssertExceptionThrown<RuntimeError>(() => a.Insert(0, 1));
            AssertExceptionThrown<RuntimeError>(() => a.InsertRange(0, new object[0]));
            AssertExceptionThrown<RuntimeError>(() => a.InsertRange(0, Enumerable(0)));
        }
开发者ID:rpattabi,项目名称:ironruby,代码行数:56,代码来源:RubyArrayTests.cs


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