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


C# Array.CopyTo方法代码示例

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


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

示例1: CombineArrays

        private static Array CombineArrays(Array arr1, Array arr2)
        {
            if (arr1 == null)
                return arr2;
            if (arr2 == null)
                return arr1;

            Array newArr = Array.CreateInstance(arr1.GetType().GetElementType(), arr1.Length + arr2.Length);
            arr1.CopyTo(newArr, 0);
            arr2.CopyTo(newArr, arr1.Length);
            return newArr;
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:12,代码来源:CXmlDriverEngine.cs

示例2: Join

 //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ��������Ӻ���
 public static Array Join(Array list1, Array list2, Type arrayType)
 {
     Array list = null;
     if (list1 != null && list2 != null)
     {
         list = Activator.CreateInstance(arrayType, list1.Length + list2.Length) as Array;
         if (list != null)
         {
             list1.CopyTo(list, 0);
             list2.CopyTo(list, list1.Length);
         }
     }
     return list;
 }
开发者ID:r1ng0to3tour,项目名称:swsplayer,代码行数:15,代码来源:ArrayUtils.cs

示例3: Add

        public static Array Add(Array aFirst, Array aSecond)
        {
            if (aFirst ==  null)
            {
                return aSecond.Clone() as Array;
            }

            if (aSecond == null)
            {
                return aFirst.Clone() as Array;
            }

            Type typeFirst = aFirst.GetType().GetElementType();
            Type typeSecond = aSecond.GetType().GetElementType();

            System.Diagnostics.Debug.Assert(typeFirst == typeSecond);

            Array aNewArray = Array.CreateInstance(typeFirst, aFirst.Length + aSecond.Length);
            aFirst.CopyTo(aNewArray, 0);
            aSecond.CopyTo(aNewArray, aFirst.Length);

            return aNewArray;
        }
开发者ID:fubar-coder,项目名称:CSFtp,代码行数:23,代码来源:ArrayHelpers.cs

示例4:

		void ICollection.CopyTo (Array array, int index)
		{
			// assuming that Nodes is a correct collection.
			array.CopyTo (Nodes.ToArray (typeof(XmlAttribute)), index);
		}
开发者ID:nobled,项目名称:mono,代码行数:5,代码来源:XmlAttributeCollection.cs

示例5: CopyTo

 public void CopyTo(Array array, int index)
 {
     array.CopyTo(array, index);
 }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:4,代码来源:MultiDimensionalArrayBindingList.cs

示例6: RotateArrayLeft

 /// <summary>
 /// Fills dest with a rotated version of source.
 /// </summary>
 /// <param name="source">The source array.</param>
 /// <param name="dest">The dest array, which must have the same length and underlying type
 /// as source.</param>
 /// <param name="rotation">The number of elements to rotate to the left by.</param>
 private static void RotateArrayLeft(Array source, Array dest, int rotation)
 {
     if (source.Length != dest.Length)
     {
         throw new ArgumentException("source and dest lengths differ.");
     }
     if (rotation == 0)
     {
         source.CopyTo(dest, 0);
     }
     else
     {
         for (int i = 0; i < source.Length; ++i)
         {
             dest.SetValue(source.GetValue((rotation + i) % source.Length), i);
         }
     }
 }
开发者ID:bejotka77,项目名称:midi-dot-net,代码行数:25,代码来源:Chord.cs

示例7: AppendToArray

 public static object[] AppendToArray(Array currentListeners, object listener) {
     var elemType = currentListeners.GetType().GetElementType();
     var newListeners = Array.CreateInstance(elemType, currentListeners.Length + 1);
     currentListeners.CopyTo(newListeners, 0);
     newListeners.SetValue(listener, currentListeners.Length);
     return (object[]) newListeners;
 }
开发者ID:FilipVV,项目名称:SolrNet,代码行数:7,代码来源:NHHelper.cs

示例8: AcquireWriteLock_ReadWrite_LocksCorrectly

        public void AcquireWriteLock_ReadWrite_LocksCorrectly()
        {
            var name = Guid.NewGuid().ToString();
            Random r = new Random();
            int bufSize = 1024;
            byte[] data = new byte[bufSize];
            byte[] readBuf = new byte[bufSize];

            bool readIsFirst = false;
            bool readBlocked = false;
            int syncValue = 0;

            // Fill with random data
            r.NextBytes(data);

            using (var sma = new Array<byte>(name, bufSize))
            {
                // Acquire write lock early
                sma.AcquireWriteLock();
                using (var smr = new Array<byte>(name))
                {
                    var t1 = Task.Factory.StartNew(() =>
                        {
                            if (System.Threading.Interlocked.Exchange(ref syncValue, 1) == 0)
                                readIsFirst = true;
                            // Should block until write lock is released
                            smr.AcquireReadLock();
                            if (System.Threading.Interlocked.Exchange(ref syncValue, 3) == 4)
                                readBlocked = true;
                            smr.CopyTo(readBuf);
                            smr.ReleaseReadLock();
                        });

                    System.Threading.Thread.Sleep(10);

                    var t2 = Task.Factory.StartNew(() =>
                        {
                            var val = System.Threading.Interlocked.Exchange(ref syncValue, 2);
                            if (val == 0)
                                readIsFirst = false;
                            else if (val == 3)
                                readBlocked = false;
                            System.Threading.Thread.Sleep(10);
                            sma.Write(data);
                            System.Threading.Interlocked.Exchange(ref syncValue, 4);
                            sma.ReleaseWriteLock();
                        });

                    Task.WaitAll(t1, t2);

                    Assert.IsTrue(readIsFirst, "The read thread did not enter first.");
                    Assert.IsTrue(readBlocked, "The read thread did not block.");

                    // Check data was written before read
                    for (var i = 0; i < readBuf.Length; i++)
                    {
                        Assert.AreEqual(data[i], readBuf[i]);
                    }
                }
            }
        }
开发者ID:rstonkus,项目名称:SharedMemory,代码行数:61,代码来源:ArrayTests.cs

示例9: CopyTo_NullArray_ThrowsException

 public void CopyTo_NullArray_ThrowsException()
 {
     var name = Guid.NewGuid().ToString();
     using (var sma = new Array<int>(name, 10))
     {
         bool exceptionThrown = false;
         try
         {
             sma.CopyTo(null);
         }
         catch (ArgumentNullException)
         {
             exceptionThrown = true;
         }
         Assert.IsTrue(exceptionThrown, "null buffer should result in ArgumentNullException");
     }
 }
开发者ID:rstonkus,项目名称:SharedMemory,代码行数:17,代码来源:ArrayTests.cs

示例10: In

 /// <summary>
 /// Creates an <see cref="InPredicate"/>.
 /// </summary>
 /// <param name="field">Database field.</param>
 /// <param name="values">List of values.</param>
 /// <param name="negate">Specifies whether the predicate is negated (NOT IN).</param>
 /// <returns>InPredicate.</returns>
 /// <remarks>Creates an IN predicate that determines if a field matches any value in a list.</remarks>
 public static InPredicate In(IDbColumn field, Array values, bool negate)
 {
     object[] objValues = new object[values.Length];
     values.CopyTo(objValues, 0);
     return In(field, objValues, negate);
 }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:14,代码来源:PredicateFactory.cs

示例11: setRow

 public void setRow(int row, Array vals)
 {
     vals.CopyTo (boxes, row * 4);
 }
开发者ID:ZombieHippie,项目名称:2048,代码行数:4,代码来源:TwentyGrid.cs

示例12: TestWriteToAndReadFrom

        public void TestWriteToAndReadFrom()
        {
            using (var map = new MemoryMapStream())
            {
                using (var memoryStream = new MemoryStream())
                {
                    using (var array = new Array<int>(map, 10))
                    {
                        for (var i = 0; i < array.Length; i++)
                        {
                            array[i] = i + 100;
                        }

                        array.CopyTo(memoryStream);
                        memoryStream.Seek(0, SeekOrigin.Begin);

                        using (var array1 = new Array<int>(map, array.Length))
                        {
                            array1.CopyFrom(memoryStream);
                            for (var i = 0; i < array.Length; i++)
                            {
                                Assert.AreEqual(array[i], array1[i]);
                            }
                        }
                    }
                }
            }

            using (var map = new MemoryMapStream())
            {
                using (var memoryStream = new MemoryStream())
                {
                    using (var array = new Array<int>(map, 10000, 32, 32, 2))
                    {
                        for (var i = 0; i < array.Length; i++)
                        {
                            array[i] = i + 100;
                        }

                        array.CopyFrom(memoryStream);
                        memoryStream.Seek(0, SeekOrigin.Begin);

                        using (var array1 = new Array<int>(map, array.Length))
                        {
                            array.CopyFrom(memoryStream);
                            for (var i = 0; i < array.Length; i++)
                            {
                                Assert.AreEqual(array[i], array1[i]);
                            }
                        }
                    }
                }
            }
        }
开发者ID:cmberryau,项目名称:reminiscence,代码行数:54,代码来源:ArrayTests.cs


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