using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// 字符串具有不可变
string str = "I am Chinese.";
// str[0] = "Y"; 错误,字符串具有不可变
string str2 = str;// str.str2字符串变量指向了同一个字符串I am Chinese.
str = "You are Chinese.";// 这并不能说明字符串改变了,只是字符串变量指向了新的字符串
Console.WriteLine(str2); // I am Chinese.
Console.ReadKey();
}
}
}
字符串具有不可变性
最新推荐文章于 2023-05-03 19:54:16 发布