- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between String.Copy() and String.CopyTo() methods in C#?
String.CopyTo() method gets the string characters and places them into an array. A group of characters are copied from source string into a character array.
The following is the Copy() method −
Example
using System; class Demo { static void Main(String[] args) { string str = "This is it!"; char[] ch = new char[5]; str.CopyTo(2, ch, 0, 2); Console.WriteLine("Output..."); Console.WriteLine(ch); } }
Output
Output... is
String.Copy() creates a new string object with similar content.
Example
using System; class Demo { static void Main(String[] args) { string str1 = "Welcome!"; string str2 = "user"; str2 = String.Copy(str1); Console.WriteLine("Output..."); Console.WriteLine(str2); } }
Output
Output... Welcome!
Advertisements