Home » C#.Net

String.Copy() method with example in C#

C# String.Copy() method: Here, we are going to learn about the Copy() method of String class with example.
Submitted by IncludeHelp, on March 18, 2019

C# String.Copy() Method

String.Copy() method is used to copy a string to new string object, it returns a new instance of String with the same value as given string.

Syntax:

    public static string Copy (string str); 

Parameter: string – whose value to be copied

Return value: string - returns a copy of the given strong.

Example:

    Input:
    string str1 = "IncludeHelp";
    
    creating new string using String.Copy() method:
    string str2 = String.Copy(str1);

    Output:
    str1: IncludeHelp
    str2: IncludeHelp

C# Example to copy a string using String.Copy() method

using System;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            string str1 = "IncludeHelp";

            //creating new string using String.Copy() method
            string str2 = String.Copy(str1);

            //printing strings
            Console.WriteLine("str1: " + str1);
            Console.WriteLine("str2: " + str2);

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output

str1: IncludeHelp
str2: IncludeHelp

Reference: String.Copy(String) Method






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.