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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP