C# String类型的字符串 问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 06:50:37
string str1 = "Persistence can produce a miracle! Unfortunately,"+"very few people can persist long enough to see a micrale happen";
string str2 = "The Secret of Success Is Persistence!";

把str1复制到str2,并输出。

代码应该怎样写?

str2=str2+str1;
Console.write("复制过后的str2{0}",str2);或者
Console.WriteLine(str2+str1);

生成新的变量的话:string str3 = string.Concat(str1, str2);
直接输出的话:Console.WriteLine("{0}{1}", str1, str2);

str2=string.copy(str1);
console.writeline(str2);

str2 += str1;
Console.write(str2);

String.Copy 方法
C#
public static string Copy ( string str )
下面是MSDN给的例子

// Sample for String.Copy()
using System;

class Sample {
public static void Main() {
string str1 = "abc";
string str2 = "xyz";
Console.WriteLine("1) str1 = '{0}'", str1);
Console.WriteLine("2) str2 = '{0}'", str2);
Console.WriteLine("Copy...");
str2 = String.Copy(str1);
Console.WriteLine("3) str1 = '{0}'", str1);
Console.WriteLine("4) str2 = '{0}'", str2);<