MSDN states that
String.Intern retrieves the system's reference to the specified String
and
String.IsInterned retrieves a reference to a specified String.
I think that IsInterned should have returned (I know it doesn't) a bool stating whether the specified string is interned or not. Is that correct thinking ? I mean it is atleast not consistent with .net framework naming convention.
I wrote the following code:
string s = "PK";
string k = "PK";
Console.WriteLine("s has hashcode " + s.GetHashCode());
Console.WriteLine("k has hashcode " + k.GetHashCode());
Console.WriteLine("PK Interned " + string.Intern("PK"));
Console.WriteLine("PK IsInterned " + string.IsInterned("PK"));
The output is :
s has hashcode -837830672
k has hashcode -837830672
PK Interned PK
PK IsInterned PK
Why is string.IsInterned("PK") returning "PK"?