コード例 #1
0
        public void AddFirstTest()
        {
            var list  = new ConcurrentLinkedList <Guid>();
            var array = Enumerable.Range(0, 4).Select(x => Guid.NewGuid()).ToArray();

            foreach (var value in array.Reverse())
            {
                list.AddFirst(value);
            }
            list.ToArray().Should().Equal(array);
        }
コード例 #2
0
        public void AddParallelTest()
        {
            var list  = new ConcurrentLinkedList <Guid>();
            var array = Enumerable.Range(0, 1024).Select(_ => Guid.NewGuid()).ToArray();

            Parallel.ForEach(array, () => - 1, (guid, state, index) =>
            {
                if (index == -1)
                {
                    return(list.AddFirst(guid));
                }
                else
                {
                    return(list.AddAfter(index, guid));
                }
            }, i => { });
            list.ToArray().Should().BeEquivalentTo(array);
        }