当前位置: 代码迷 >> 综合 >> 字符串具有不可变性
  详细解决方案

字符串具有不可变性

热度:39   发布时间:2024-01-17 03:40:11.0
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();}}}


  相关解决方案