C#Copy()方法
C#中的Copy()方法用于创建具有与指定String相同值的String的新实例。
语法
public static string Copy (string s);
在上面,s是要复制的字符串。
示例
using System;
public class Demo {
public static void Main(string[] args) {
string s1 = "Amy";
string s2 = "Katie";
string s3 = String.Copy(s2);
Console.WriteLine("String1 = "+s1);
Console.WriteLine("String2 = "+s2);
Console.WriteLine("Are both the strings equal? = "+s1.Equals(s2));
Console.WriteLine("Are both the strings equal? = "+s2.Equals(s3));
Console.WriteLine(string.CompareOrdinal(s1, s2));
Console.WriteLine(string.CompareOrdinal(s2, s3));
}
}输出结果
String1 = Amy String2 = Katie Are both the strings equal? = False Are both the strings equal? = True -10 0
示例
using System;
public class Demo {
public static void Main(string[] args) {
string s1 = "Gary";
string s2 = "Gary";
string s3 = String.Copy(s2);
Console.WriteLine("String1 = "+s1);
Console.WriteLine("String2 = "+s2);
Console.WriteLine("Is s1 and s2 equal? = "+s1.Equals(s2));
Console.WriteLine("Is s2 and s3 equal? = "+s2.Equals(s3));
s3 = "Harry";
Console.WriteLine("Is s2 and s3 equal? = "+s2.Equals(s3));
}
}输出结果
String1 = Gary String2 = Gary Is s1 and s2 equal? = True Is s2 and s3 equal? = True Is s2 and s3 equal? = False
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短