当前位置: 首页>>代码示例>>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;未经允许,请勿转载。