I read somewhere that if you have multiple strings in your application that are the same, that there is really only ever one created and all references really point to the same string.
That is incorrect. Although you can arrange your program in such a way that it used a single object per unique string, .NET does not make such guarantee. It is true that C# compiler will make all string
objects produced from string literals in your program point to the same string object. However, it is rather easy to create multiple string
objects with identical content.
if I wanted to compare two strings, is there any way to do it by their memory location?
You can use Object.ReferenceEquals
method for that:
public bool areSame(string s1,string s2){
return Object.ReferenceEquals(s1, s2);
}