How should i be handling string Interning on deserialization?

Posted by DayOne on Stack Overflow See other posts from Stack Overflow or by DayOne
Published on 2010-06-03T11:56:29Z Indexed on 2010/06/03 12:04 UTC
Read the original article Hit count: 198

Filed under:
|

In the example below I am interning the string in the constructor which is fine. However when i deserialise the object from the binary formatter I don't think the string will be interned as the constructor should be called. How should I be ensuring the _name string is interned? ... or will it be interned ok?

Thanks

[Serializable]
class City
{
    private readonly string _name;

    public City(string t)
    {
        _name = string.Intern(t);
    }

    public string Name
    {
        get { return _name; }
    }

    public override string ToString()
    {
        return _name;
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about string-interning