Occasionally I've found that string
implements IClonable
interface and I wondered why, since string is immutable. Further I tried to guess how it should work and what to expect from cloning a string... I expected it should return same string reference when string interning is enabled, and create new object in case it is disabled (I undertand that in that case equality operator wouldn't have worked correctly anymore - probably that's why it isn't implemented this way).
When I decompiled the method from .NET sources - I found that the implementation is just returning self-reference (this
pointer) without any extra logic. And there is a comment on it:
// Method required for the ICloneable interface.
// There's no point in cloning a string since they're immutable, so we simply return this.
So .NET team themselves say there is no point calling this method. But why did they implement it at all then?