

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to copy a String into another String in C#
To copy a String into another String, the code is as follows −
Example
using System; public class Demo { static public void Main(){ string str1 = "Kevin"; string str2 = String.Copy(str1); Console.WriteLine("String1 = "+str1); Console.WriteLine("String2 = "+str2); } }
Output
This will produce the following output −
String1 = Kevin String2 = Kevin
Example
Let us now see another example −
using System; public class Demo { static public void Main(){ string str1 = "Maisie"; string str2 = "Ryan"; Console.WriteLine("String1 (Before copying) = "+str1); Console.WriteLine("String2 (Before copying) = "+str2); str2 = String.Copy(str1); Console.WriteLine("String1 = "+str1); Console.WriteLine("String2 (Updated) = "+str2); } }
Output
This will produce the following output −
String1 (Before copying) = Maisie String2 (Before copying) = Ryan String1 = Maisie String2 (Updated) = Maisie
- Related Questions & Answers
- Insert a String into another String in Java
- Java Program to Insert a string into another string
- String Transforms Into Another String in Python
- Copy characters from string into char Array in Java
- Print all possible ways to convert one string into another string in C++
- How to copy a section of an array into another array in C#?
- How to insert a string in beginning of another string in java?
- In MySQL, how can we pad a string with another string?
- How to split a string into elements of a string array in C#?
- How to check if a string is a subset of another string in R?
- How to replace all occurrences of a string with another string in Python?
- Program to check whether one string can be 1-to-1 mapped into another string in Python
- How do I determine if a String contains another String in Java?
- Copy char array to string in Java
- How to convert a String into int in Java?
Advertisements