01
public
static
void
RunSnippet()
02 {
03 string s = "aa";
04 string s1 = "aa";
05 string s2 = "a" + "a";
06 string s3 = "a";
07 string s4 = s3 + "a";
08 WL(s . GetHashCode());
09 WL( s1 . GetHashCode());
10 WL( s2 . GetHashCode());
11 WL( s3 . GetHashCode());
12 WL( s4 . GetHashCode());
13 GetStr(s);
14 WL(s . GetHashCode());
15 }
16
17 private static void GetStr( string s)
18 {
19 WL(s . GetHashCode());
20 s = "cccc";
21 WL(s . GetHashCode());
22 }
02 {
03 string s = "aa";
04 string s1 = "aa";
05 string s2 = "a" + "a";
06 string s3 = "a";
07 string s4 = s3 + "a";
08 WL(s . GetHashCode());
09 WL( s1 . GetHashCode());
10 WL( s2 . GetHashCode());
11 WL( s3 . GetHashCode());
12 WL( s4 . GetHashCode());
13 GetStr(s);
14 WL(s . GetHashCode());
15 }
16
17 private static void GetStr( string s)
18 {
19 WL(s . GetHashCode());
20 s = "cccc";
21 WL(s . GetHashCode());
22 }
1 string是final不可以改变的
2 string pool的使用,因为string类型在C#中经常使用
3 s = "ccc"其实是新建了一个新的实例。
2 string pool的使用,因为string类型在C#中经常使用
3 s = "ccc"其实是新建了一个新的实例。