Quote:
|
Small difference doesnt mean it uses references to compare. And why should it mean something like that?
|
See quote below.
Quote:
|
integer comparisons dont use reference comparisons..
|
Integers don't need to. They are a unique number. You can use a single assembler instruction to compare them per se. Strings don't have that property on any modern silicon I know of. So they are "internalized" in such a fashion that any two strings that are spelled the same (are "lexigraphically identical" is the technical term) have the same address in memory. You can then know that if the address is the same, they are the same string, and if not, not.
C# internalizes strings and does reference comparison for equality check by default. Why? Because it's the
only fast way to do this. It's also memory-compact, which is why any virtual machine worth its salt
always uses string internalization.
But by all means, don't believe
me. Here's a direct quote from MSDN:
Quote:
|
The common language runtime conserves string storage by maintaining a table, called the intern pool, that contains a single reference to each unique literal string declared or created programmatically in your program. Consequently, an instance of a literal string with a particular value only exists once in the system. For example, if you assign the same literal string to several variables, the runtime retrieves the same reference to the literal string from the intern pool and assigns it to each variable.
|
I suppose, thinking about it, it would be possible to assign a unique number to a master object, and compare that number itself. Same/same. And kind of pointless. The address of any object in the table is a unique number itself.
C//