Subject: Credential Report - (View Details)

From: Neighborhood Criminal Records <[email-masked]>
Date: Wed, 14 May 2014 12:51:09 -0700

ATTN Ipp-archive

For Instant background check on person of your choice

Enter Name Here: http://www.bubwan.com/report/background/criminal.pdf

>> Records Compiled from local, state and federal records <<

Classified Info In Report to Include:
=====================================
Criminal Records
Judgements & Liens
Previous Addresses
Phone Numbers
Social Media Accounts
Emails

modify sub status w/ Urgent Info Services 
3205 Lake Sarah
Independence, MN 55359
or visiting http://www.bubwan.com/k34ntf.sgni 

This is true, however it is just another allocation. If one more allocation on the class is going to break your heart you can make the class a struct and then you're back to a single allocation for Setter and the string reference text. 99% of the time, for 99% of the software folks write, the extra allocation matters less than keeping the intent of the code honest. We don't all suffer Assult by GC, few of us work with StackOverflow type volumes :p  Binary Worrier Apr 14 at 9:56

 . . with the obvious caveat that you'd need to implement the struct properly (i.e. as an immutable type), which means you're back to an allocation for every assignment . . . maybe don't make the class a struct. Binary Worrier Apr 14 at 10:17

creating a new struct each time is not an allocation; the size would be the size of the contained data, presumably a single string reference - so no larger than the original  Marc Gravell Apr 14 at 10:36

So something like this.myDate = new DateTime(2014, 04, 14); doesn't cause an allocation? This I did not know. It looks like it does, the new to create a new struct, which would then be copied over the old. I may look into this and see how it actually works, thanks.  Binary Worrier Apr 14 atternal struct SanitizedText {
    private readonly string value;
    private SanitizedText(string value) {
        this.value = value;
    }
    public static implicit operator string (SanitizedText value) {
        return value.value;
    }
    public static implicit operator SanitizedText(string value) {
        if (value != null) value = value.Replace('a', 'b');
        return new SanitizedText(value);
    }
}
and then simply:
private SanitizedText text;
public string Text {
    get { return text; }
    set { text = value; }
}
This does all the same validation, but it is impossible to abuse: you cannot create a SanitizedTextvalue that bypasses the validation; equally, it takes no more space (the size of the struct is the size of the contents: 1 reference), and requires no allocations. It even defaults to a null string in the same way.