當前位置: 首頁>>代碼示例>>C#>>正文


C# Array.Clone方法代碼示例

本文整理匯總了C#中System.Array.Clone方法的典型用法代碼示例。如果您正苦於以下問題:C# Array.Clone方法的具體用法?C# Array.Clone怎麽用?C# Array.Clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Array的用法示例。


在下文中一共展示了Array.Clone方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ReverseArray

    /// <summary>
    /// Returns a new array containing the input array's elements in reverse order.
    /// </summary>
    /// <param name="input">The input array.</param>
    /// <returns>A reversed clone of the input array.</returns>
    public static Array ReverseArray(Array input)
    {
        Array clone = (Array)input.Clone();
        for (int g = 0; g < clone.Length; g++)
        {
            clone.SetValue(input.GetValue(input.Length - g - 1), g);
        }

        return clone;
    }
開發者ID:nnyamhon,項目名稱:corefx,代碼行數:15,代碼來源:Array.Util.cs

示例2: 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

示例3: AssertArrayEqualsSorted

		private static void AssertArrayEqualsSorted (Array o1, Array o2)
		{
			Array s1 = (Array) o1.Clone ();
			Array s2 = (Array) o2.Clone ();

			Array.Sort (s1);
			Array.Sort (s2);

			Assert.AreEqual (s1.Length, s2.Length, "#1");
			for (int i = 0; i < s1.Length; ++i)
				Assert.AreEqual (s1.GetValue (i), s2.GetValue (i), "#2: " + i);
		}
開發者ID:user277,項目名稱:mono,代碼行數:12,代碼來源:ModuleBuilderTest.cs

示例4: InternalSort

		/// <summary>
		/// The actual implementation
		/// </summary>
		/// <param name="primary"></param>
		/// <param name="left"></param>
		/// <param name="right"></param>
		/// <param name="compare"></param>
		protected void InternalSort(
		ref Array primary,
		int left,
		int right,
		System.Collections.IComparer compare)
		{
			if (secondary == null || secondary.Length != primary.Length)
				secondary = (Array)primary.Clone();

			if (right > left)
			{
				int middle = (left + right) / 2;
				InternalSort(ref primary, left, middle, compare);
				InternalSort(ref primary, middle + 1, right, compare);

				int i, j, k;
				for (i = middle + 1; i > left; i--)
					secondary.SetValue(primary.GetValue(i - 1), i - 1);
				for (j = middle; j < right; j++)
					secondary.SetValue(primary.GetValue(j + 1), right + middle - j);
				for (k = left; k <= right; k++)
					primary.SetValue(
					(compare.Compare(secondary.GetValue(i), secondary.GetValue(j)) < 0) ?
					secondary.GetValue(i++) :
					secondary.GetValue(j--), k);
			}
		}
開發者ID:sillsdev,項目名稱:FieldWorks,代碼行數:34,代碼來源:MergeSort.cs

示例5: GetMergedArray

        private static Array GetMergedArray(object selected, Array oldArray, Array newArray, bool[] equalComponents)
        {
            Array result = newArray;
            if (oldArray != null)
            {
                result = (Array)oldArray.Clone();
                for (int i = 0; i < newArray.Length; i++)
                    if (!equalComponents[i])
                        result.SetValue(newArray.GetValue(i), i);
            }

            return result;
        }
開發者ID:sbambach,項目名稱:ATF,代碼行數:13,代碼來源:PropertyEditorControlContext.cs

示例6: PutData

        /// <summary>Writes the data to the wrapped array starting with the specified origin indices.
        /// </summary>
        /// <param name="origin">Indices to start adding of data. Null means all zeros.</param>
        /// <param name="a">Data to add to the variable.</param>
        public virtual void PutData(int[] origin, Array a)
        {
            if (a == null) return;
            if (rank == 0)
            {
                if (a.Rank != 1)
                    throw new Exception("Wrong rank");
                array.SetValue(a.GetValue(0), 0);
                return;
            }

            if (rank != a.Rank)
                throw new Exception("Wrong rank");

            int[] shape = null;

            if (array == null)
            {
                if (origin == null || IsZero(origin))
                {
                    array = (Array)a.Clone();
                    return;
                }

                shape = new int[rank];
                for (int i = 0; i < rank; i++)
                    shape[i] = origin[i] + a.GetLength(i);

                array = Array.CreateInstance(type, shape);
                CopyArray(a, array, new int[origin.Length], origin, true);
            }
            else
            {
                Array oldArr = array;

                if (origin == null)
                    origin = new int[rank];

                shape = new int[array.Rank];
                bool sufficient = true;
                for (int i = 0; i < array.Rank; i++)
                {
                    int size = origin[i] + a.GetLength(i);
                    sufficient = sufficient && (size <= oldArr.GetLength(i));

                    shape[i] = Math.Max(size, oldArr.GetLength(i));
                }

                Array newArr;
                if (sufficient)
                {
                    newArr = oldArr;
                }
                else
                {
                    newArr = Array.CreateInstance(type, shape);
                    CopyArray(oldArr, newArr, new int[array.Rank], new int[array.Rank],true);
                }

                if (origin == null)
                    origin = new int[array.Rank];
                CopyArray(a, newArr, new int[origin.Length], origin, true);
                array = newArr;
            }

            return;// shape;
        }
開發者ID:modulexcite,項目名稱:SDSlite,代碼行數:71,代碼來源:ArrayWrapper.cs


注:本文中的System.Array.Clone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。