So I have this;
var emailA = ConstructEmailA();
SnedEmailA(emailA.Append("</body>").ToString());
var emailB = ConstructEmailB(emailA);
SendEmailB(emailB.ToString());
Which works fine. Essentially, ConstructEmailB takes emailA and adds to it. However, I originally had this:
var emailA = ConstructEmailA();
var emailB = ConstructEmailB(emailA);
SnedEmailA(emailA.Append("</body>").ToString());
SendEmailB(emailB.ToString());
Which did not work as expected. Instead of emailA and emailB being different, emailA contained the same info as emailB. How come?
Here is my ConstructEmailB method:
private StringBuilder ConstructEmailB(StringBuilder email)
{
email.Append("Append stuff");
return email;
}
Because
emailAisemailB. They are both references to the sameStringBuilderobject, the only difference being when you callSendEmail. In the first case youemailA.emailA.SendEmailA.emailB, which is really just appending toemailAand then send that.In case 2 you have:
emailAandemailB. They are identical because they are both references to the sameStringBuilder.'to emailA (and thus, also toemailB) and send it.emailB.