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


C# Mapper.RemoveAt方法代码示例

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


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

示例1: SetToNull

        public void SetToNull()
        {
            var mapper = new Mapper<string>();
            string result;
            bool isNew;

            Assert.IsTrue(mapper.Insert(0, null));
            Assert.IsTrue(mapper.TryGet(0, out result));
            Assert.AreEqual(null, result);

            Assert.IsTrue(mapper.RemoveAt(0, out result));
            Assert.AreEqual(null, result);

            Assert.IsTrue(mapper.Exchange(0, null, out result));
            Assert.AreEqual(null, result);

            Assert.IsFalse(mapper.Insert(0, null, out result));
            Assert.AreEqual(null, result);

            mapper.Set(0, "Hello", out isNew);
            Assert.IsFalse(isNew);
            Assert.IsTrue(mapper.TryGet(0, out result));
            Assert.AreEqual("Hello", result);

            mapper.Set(0, null, out isNew);
            Assert.IsFalse(isNew);
            Assert.IsTrue(mapper.TryGet(0, out result));
            Assert.AreEqual(null, result);

            mapper.Exchange(0, "Hello", out result);
            Assert.AreEqual(null, result);

            mapper.Exchange(0, null, out result);
            Assert.AreEqual("Hello", result);

            Assert.AreEqual(1, mapper.Count);
        }
开发者ID:vebin,项目名称:Theraot.Collections.ThreadSafe,代码行数:37,代码来源:MapperTests.cs

示例2: TwoThreadsRemoveAt

        public void TwoThreadsRemoveAt()
        {
            var mapper = new Mapper<int>();
            const int Input = 21;
            var info = new CircularBucket<string>(16);

            var startEvent = new ManualResetEvent(false);
            int[] done = {0};
            var threads = new[]
            {
                new Thread
                (
                    () =>
                    {
                        int result;
                        bool isNew;
                        mapper.Set(0, Input, out isNew);
                        info.Add("A: Set - was new: " + isNew);
                        bool removed = mapper.RemoveAt(0, out result);
                        info.Add(removed ? "A: Removed" : "A: Could not remove");
                        Interlocked.Increment(ref done[0]);
                    }
                ),
                new Thread
                (
                    () =>
                    {
                        int result;
                        bool isNew;
                        mapper.Set(0, Input, out isNew);
                        info.Add("B: Set - was new: " + isNew);
                        bool removed = mapper.RemoveAt(0, out result);
                        info.Add(removed ? "B: Removed" : "B: Could not remove");
                        Interlocked.Increment(ref done[0]);
                    }
                )
            };
            threads[0].Start();
            threads[1].Start();
            startEvent.Set();
            while (true)
            {
                if (Thread.VolatileRead(ref done[0]) == 2)
                {
                    break;
                }
                Thread.Sleep(0);
            }
            Assert.AreEqual(0, mapper.Count);
        }
开发者ID:vebin,项目名称:Theraot.Collections.ThreadSafe,代码行数:50,代码来源:MapperTests.cs

示例3: RemoveAt

        public void RemoveAt()
        {
            var mapper = new Mapper<int>();
            const int Input = 21;
            int result;
            bool isNew;

            //---

            mapper.Set(0, Input, out isNew);
            Assert.IsTrue(isNew);
            Assert.IsTrue(mapper.TryGet(0, out result));
            Assert.AreEqual(Input, result);

            Assert.IsTrue(mapper.RemoveAt(0, out result));
            Assert.AreEqual(Input, result);
            Assert.IsFalse(mapper.TryGet(0, out result));

            Assert.IsFalse(mapper.RemoveAt(1, out result));
            Assert.IsFalse(mapper.TryGet(1, out result));

            //---

            mapper.Set(0, Input, out isNew);
            Assert.IsTrue(isNew);
            Assert.IsTrue(mapper.TryGet(0, out result));
            Assert.AreEqual(Input, result);

            Assert.IsTrue(mapper.RemoveAt(0));
            Assert.IsFalse(mapper.TryGet(0, out result));

            Assert.IsFalse(mapper.RemoveAt(1));
            Assert.IsFalse(mapper.TryGet(1, out result));

            Assert.AreEqual(0, mapper.Count);
        }
开发者ID:vebin,项目名称:Theraot.Collections.ThreadSafe,代码行数:36,代码来源:MapperTests.cs


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