why does ReferenceEquals(s1,s2) returns true

前端 未结 5 1478
遥遥无期
遥遥无期 2021-01-07 23:52
  String s1 = \"Hello\";
  String s2 = \"Hello\";

Here s1, s2 are different but then why ReferenceEquals() is returning true

5条回答
  •  星月不相逢
    2021-01-08 00:21

    You also can use String.Copy(String str) static method to create strings that will be different objects

    String s1 = "Hello";
    String s2 = string.Copy("Hello");
    

    then s1 and s2 will be referencing different objects.

提交回复
热议问题