Are .NET resource file strings interned?
Asked Answered
C

1

3

When I use a .resx file to store fixed string values (to be bound to controls on an .aspx page), are these strings interned?

I presume the compiler reads in the strings from the XML file and replaces them as literals in the code, and therefore they become interned.

Is this correct?

Companionate answered 20/1, 2011 at 9:39 Comment(2)
What does string.IsInterned(example) return?Carnation
I don't mean they are replaced as literals, actually, I don't know what happens, I'm just assuming they are injected as strings at compile-time, as they are not run-time changable, as I understand it.Companionate
C
0

@Marc- good point. I tried it and the answer is, 'no', they're not interned, at least for the GetGlobalResourceObject() method, so I assume the same for local resources.

So, now I wonder why. Resources are meant to be constants and they are frequently used, so I would have thought interning makes sense.

Obviously, they're not literals, as they must be loaded from the XML resources file, but that shouldn't matter, should it?

Companionate answered 20/1, 2011 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.