C#的String.Copy()方法示例
C#方法String.Copy()
String.Copy()方法用于将字符串复制到新的字符串对象,它返回具有与给定字符串相同值的String的新实例。
语法:
public static string Copy (string str);
参数:string-要复制其值的字符串
返回值:字符串-返回给定强度的副本。
示例
Input:
string str1 = "nhooo";
creating new string using String.Copy() method:
string str2 = String.Copy(str1);
Output:
str1: nhooo
str2: nhoooC#使用方法复制字符串的示例String.Copy()
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
string str1 = "nhooo";
//使用String.Copy()方法创建新的字符串
string str2 = String.Copy(str1);
//打印字符串
Console.WriteLine("str1: " + str1);
Console.WriteLine("str2: " + str2);
//按ENTER退出
Console.ReadLine();
}
}
}输出结果
str1: nhooo str2: nhooo
参考:方法String.Copy(String)
热门推荐
10 高一祝福语简短 励志
11 立秋节气简短祝福语
12 简短公司周年祝福语大全
13 中考感言简短祝福语大全
14 体育老师简短祝福语
15 干杯生日祝福语简短独特
16 特别简短的祝福语老师
17 朋友坐车走了祝福语简短
18 给英雄的祝福语简短