相关疑难解决方法(0)

在C#中,为什么String是一个行为类似值的引用类型?

String是一种引用类型,即使它具有值类型的大多数特性,例如是不可变的并且具有==重载以比较文本而不是确保它们引用相同的对象.

为什么字符串不是一个值类型呢?

c# string clr value-type reference-type

348
推荐指数
8
解决办法
16万
查看次数

c#字符串是引用类型 - 为什么当我更改引用A的值时,引用B不会改变?

如果.NET中的字符串是引用类型,在下面的代码中,为什么string1更改后string2不会更改为"hi"?

static void IsStringReallyAReference()
{
    string string1 = "hello";
    string string2 = string1;

    Console.WriteLine("-- Strings --");
    Console.WriteLine(string1);
    Console.WriteLine(string2);

    string1 = "hi";

    Console.WriteLine(string1);
    Console.WriteLine(string2);
    Console.Read();

}

/*Output:
hello
hello
hi
hello*/
Run Code Online (Sandbox Code Playgroud)

.net c# string reference-type

1
推荐指数
2
解决办法
300
查看次数

标签 统计

c# ×2

reference-type ×2

string ×2

.net ×1

clr ×1

value-type ×1