Part 34.String Copy() in c#

String Copy() : string.copy() method copy the string data to another specified string. and its return type is string. It is static method of the string class.

Syntax :

                public static string Copy(string str);

This method accepts single parameter str which is the original string to be copied.

The type of Copy() method is System.String.

Important point :

  1. string.Copy() : you are actually allocating new memory and copying the characters from one string to another; 
                       string copy =  string.copy(otherString);

class Program
{
        {
            string  str = "csharp-tutorial-point";
            string  data = string.copy(6);
            System.Console.WriteLine("Copy the string : "+data);
            System.Console.ReadLine();
        }
    }

Output :

Copy  the string : csharp-tutorial-point


Array.CopyTo copies all the elements of the current array to the specified destination array. 


class Program

    {
        static void Main(string[] args)
        {
            var source = new[] { "C#", "Tutorial", "Chandan" };
            var target = new string[4];
            source.CopyTo(target, 1);
            foreach (var item in target)
            {
                System.Console.WriteLine(item);
            }

           System.Console.ReadLine();

        }
    }
Output :

C#,

Tutorial,