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


C# System.Clone方法代码示例

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


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

示例1: printParenth

 private static void printParenth(int left, int right, System.Collections.ArrayList arr)
 {
     if (left == 0 && right == 0)
     {
         foreach (var item in arr)
         {
             System.Console.Write(item + " ");
         }
         System.Console.WriteLine();
         //return arr;
     }
     if (left > 0)
     {
         System.Collections.ArrayList new_arr = (System.Collections.ArrayList)arr.Clone();
         new_arr.Add("(");
         //return
         printParenth(left - 1, right, new_arr);
     }
     if (left < right)
     {
         System.Collections.ArrayList new_arr = (System.Collections.ArrayList)arr.Clone();
         new_arr.Add(")");
         //return
         printParenth(left, right - 1, new_arr);
     }
     //return null;
 }
开发者ID:Sanqiang,项目名称:Algorithm-Win,代码行数:27,代码来源:CC8_5.cs

示例2: printParenth

        private static void printParenth(int RemainingLeft, int RemainingRight, System.Collections.ArrayList arr)
        {
            if (RemainingLeft == 0 && RemainingRight == 0)
            {
                for (int i = 0; i < arr.Count; i++)
                {
                    System.Console.Write(arr[i] + " ");
                }
                System.Console.WriteLine();
            }

            if (RemainingLeft > 0)
            {
                System.Collections.ArrayList arr2 = (System.Collections.ArrayList)arr.Clone();
                arr2.Add("[");
                printParenth(RemainingLeft - 1, RemainingRight, arr2);

            }

            if (RemainingLeft < RemainingRight)
            {
                System.Collections.ArrayList arr2 = (System.Collections.ArrayList)arr.Clone();
                arr2.Add("]");
                printParenth(RemainingLeft, RemainingRight - 1, arr2);
            }
        }
开发者ID:Sanqiang,项目名称:Algorithm-Win,代码行数:26,代码来源:Q46.cs

示例3: RunArrayRotation

        private static void RunArrayRotation()
        {
            var inputArray = new[] { 1, 2, 3, 4, 5, 6 };
            var positions = 2;
            Console.WriteLine($"Input: {Utils.FormatArray(inputArray)}, rotate by: {positions}");
            var arrayCopy = (int[])inputArray.Clone();
            ArrayRotation.Rotate(arrayCopy, positions);
            Console.WriteLine($"Rotate: {Utils.FormatArray(arrayCopy)}");

            arrayCopy = (int[])inputArray.Clone();
            ArrayRotation.Rotate_Reverse(arrayCopy, positions);
            Console.WriteLine($"Rotate by using array reverse: {Utils.FormatArray(arrayCopy)}");
        }
开发者ID:moozzyk,项目名称:AlgorithmsInCSharp,代码行数:13,代码来源:MiscAlgorithmsRunner.cs

示例4: CloneWorks

 public void CloneWorks()
 {
     var arr = new[] { "x", "y" };
     var arr2 = arr.Clone();
     Assert.IsFalse(arr == arr2);
     Assert.AreEqual(arr, arr2);
 }
开发者ID:jack128,项目名称:SaltarelleCompiler,代码行数:7,代码来源:ArrayTests.cs

示例5: Image

        public Image(System.Drawing.Bitmap bitmap)
        {
            this.bitmap = (System.Drawing.Bitmap)bitmap.Clone();

            this.width = this.bitmap.Width;
            this.height = this.bitmap.Height;
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:7,代码来源:Image.cs

示例6: Recombine

        public System.Collections.ArrayList Recombine(System.Collections.ArrayList maleGenes, System.Collections.ArrayList femaleGenes)
        {
            ArrayList child;

            if (maleGenes.Count < femaleGenes.Count)
            {
                child = femaleGenes.Clone() as ArrayList;
                for (int i = 0; i < maleGenes.Count; i++)
                {
                    if (!Convert.ToBoolean(i % 2))
                        child[i] = maleGenes[i];
                    // Deep Copy
                    child[i] = (child[i] as IGene).Clone();
                }
            }
            else
            {
                child = maleGenes.Clone() as ArrayList;
                for (int i = 0; i < femaleGenes.Count; i++)
                {
                    if (!Convert.ToBoolean(i % 2))
                        child[i] = femaleGenes[i];
                    // Deep Copy
                    child[i] = (child[i] as IGene).Clone();
                }
            }
            return child;
        }
开发者ID:DanielBaulig,项目名称:Genetic-Algorithms,代码行数:28,代码来源:AsymmetricZipRecombinator.cs

示例7: DirectXTexture

        /// <summary>
        /// Initializes a new DirectXTexture class.
        /// </summary>
        /// <param name="bmp">The Bitmap.</param>
        internal DirectXTexture(System.Drawing.Bitmap bmp)
        {
            RawBitmap = (System.Drawing.Bitmap) bmp.Clone();
            _width = bmp.Width;
            _height = bmp.Height;
            var sourceArea = new Rectangle(0, 0, bmp.Width, bmp.Height);
            var bitmapProperties = new BitmapProperties(
                new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied), 96, 96);
            var size = new Size2(bmp.Width, bmp.Height);

            int stride = bmp.Width*sizeof (int);
            using (var tempStream = new DataStream(bmp.Height*stride, true, true))
            {
                BitmapData bitmapData = bmp.LockBits(sourceArea, ImageLockMode.ReadOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                for (int y = 0; y < bmp.Height; y++)
                {
                    int offset = bitmapData.Stride*y;
                    for (int x = 0; x < bmp.Width; x++)
                    {
                        byte b = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte g = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte r = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte a = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        int rgba = r | (g << 8) | (b << 16) | (a << 24);
                        tempStream.Write(rgba);
                    }
                }
                bmp.UnlockBits(bitmapData);
                tempStream.Position = 0;
                _bmp = new Bitmap(DirectXHelper.RenderTarget, size, tempStream, stride, bitmapProperties);
            }
        }
开发者ID:ThuCommix,项目名称:Sharpex2D,代码行数:38,代码来源:DirectXTexture.cs

示例8: Resize

        /// <summary>
        /// Resizes and rotates an image, keeping the original aspect ratio. Does not dispose the original
        /// Image instance.
        /// </summary>
        /// <param name="image">Image instance</param>
        /// <param name="width">desired width</param>
        /// <param name="height">desired height</param>
        /// <param name="rotateFlipType">desired RotateFlipType</param>
        /// <returns>new resized/rotated Image instance</returns>
        public static System.Drawing.Image Resize(System.Drawing.Image image, int width, 
            int height, RotateFlipType rotateFlipType)
        {
            // clone the Image instance, since we don't want to resize the original Image instance
            var rotatedImage = image.Clone() as System.Drawing.Image;
            //rotatedImage.RotateFlip(rotateFlipType);
            var newSize = CalculateResizedDimensions(rotatedImage, width, height);

            var resizedImage = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format32bppArgb);
            resizedImage.SetResolution(72, 72);

            using (var graphics = Graphics.FromImage(resizedImage))
            {
                // set parameters to create a high-quality thumbnail
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                // use an image attribute in order to remove the black/gray border around image after resize
                // (most obvious on white images), see this post for more information:
                // http://www.codeproject.com/KB/GDI-plus/imgresizoutperfgdiplus.aspx
                using (var attribute = new ImageAttributes())
                {
                    attribute.SetWrapMode(WrapMode.TileFlipXY);

                    // draws the resized image to the bitmap
                    graphics.DrawImage(rotatedImage, new Rectangle(new Point(0, 0), newSize), 0, 0, rotatedImage.Width, rotatedImage.Height, GraphicsUnit.Pixel, attribute);
                }
            }

            return resizedImage;
        }
开发者ID:tonousa,项目名称:HtmlEmails,代码行数:42,代码来源:WebForm.aspx.cs

示例9: P4FormRecordSet

 internal P4FormRecordSet(string FormCommand, System.Text.Encoding encoding)
 {
     // clone this so we don't hold a reference to another object's encoding object
     // preventing it from Garbage collecting.
     _encoding = (System.Text.Encoding) encoding.Clone();
     _FormCommand = FormCommand;
 }
开发者ID:orecht,项目名称:P4.net,代码行数:7,代码来源:P4FormRecordSet.cs

示例10: VersionAttribute

 public VersionAttribute(System.Version version)
 {
     if (version == null)
     {
         throw new ArgumentNullException();
     }
     this.Version = (System.Version) version.Clone();
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:8,代码来源:VersionAttribute.cs

示例11: SortingWithoutChanges

        public void SortingWithoutChanges()
        {
            var array = new[] { 1, 2, 3, 4, 5 };
            var arrayCopy = (int[])array.Clone();

            array.HeapSort();

            CollectionAssert.AreEqual(arrayCopy, array);
        }
开发者ID:Confirmit,项目名称:Students,代码行数:9,代码来源:HeapSortTests.cs

示例12: SortingSomeArray

        public void SortingSomeArray()
        {
            var array = new[] { -5, 5, -10, -4, 11, 0, 1, -9, 9, 7 };
            var arrayCopy = (int[])array.Clone();

            array.HeapSort();
            Array.Sort(arrayCopy);

            CollectionAssert.AreEqual(arrayCopy, array);
        }
开发者ID:Confirmit,项目名称:Students,代码行数:10,代码来源:HeapSortTests.cs

示例13: P4Form

 internal P4Form(string FormCommand, string specDef, Dictionary<string, string> S, System.Text.Encoding encoding)
     : base(S)
 {
     _specdef = specDef;
     // clone this so we don't hold a reference to another object's encoding object
     // preventing it from Garbage collecting.
     _encoding = (System.Text.Encoding) encoding.Clone();
     _spec = new p4dn.Spec(specDef, encoding);
     _formCommand = FormCommand;
 }
开发者ID:orecht,项目名称:P4.net,代码行数:10,代码来源:P4Form.cs

示例14: SortingBadArray

        public void SortingBadArray()
        {
            var array = new[] { 5, 4, 3, 2, 1 };
            var arrayCopy = (int[])array.Clone();

            array.HeapSort();
            Array.Sort(arrayCopy);

            CollectionAssert.AreEqual(arrayCopy, array);
        }
开发者ID:Confirmit,项目名称:Students,代码行数:10,代码来源:HeapSortTests.cs

示例15: SortingSomeArrayWhenMaxComparerUsing

        public void SortingSomeArrayWhenMaxComparerUsing()
        {
            var array = new[] { -5, 5, -10, -4, 11, 0, 1, -9, 9, 7 };
            var arrayCopy = (int[])array.Clone();
            var comparer = new MyIntComparer();

            array.HeapSort(comparer);
            Array.Sort(arrayCopy, comparer);

            CollectionAssert.AreEqual(arrayCopy, array);
        }
开发者ID:Confirmit,项目名称:Students,代码行数:11,代码来源:HeapSortTests.cs


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