using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace copyclonecopyto
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("--------------CLONE-------------------------");
string s = "anurag";
//object s1 = s.Clone();
object s2 = s.Clone();
Console.WriteLine(s2.ToString());//anu
Console.WriteLine("--------------COPY-------------------------");
string s3 = string.Copy(s);
Console.WriteLine(s3);
Console.WriteLine("--------------COPY TO-------------------------");
char[] chars = new char[15];
////s.CopyTo(0, chars, 1, 3);
//s.CopyTo(1, chars, 0, 2);//nu
//s.CopyTo(1, chars, 0, 5);//nurag
////s.CopyTo(1, chars, 0, 6);//error
//s.CopyTo(0, chars, 0, 6);//anurag
//s.CopyTo(0, chars, 10, 6);//error as maximum limit is 15
s.CopyTo(0, chars, 9, 6);//you get the output as :9 spaces are left blank : anurag
//s.CopyTo(2, chars, 0, 6);//error:Index and count must refer to a location within the string.
//s.CopyTo(int sourceindex,char destination,destination index ,count)
Console.WriteLine(chars);
Console.ReadLine();
}
}
}
/*
cloning is used to create an object thats based on your string
*/
No comments:
Post a Comment