Can anyone explain to me why these two are different functionally?
The first returns null on my sample data, and the second returns the expected result. I put the + @"" part in to avoid calling replace on a null string.
Code always returns null on my sample data:
to_follows_contact = db.CONTACTs.Where(n =>
n.ACCOUNTID == account.ACCOUNTID
&& (
(n.FIRSTNAME + n.MIDDLENAME + n.LASTNAME + @"").Replace(@" ", @"")
== @"TOFOLLOW"
||
(n.FIRSTNAME + n.MIDDLENAME + n.LASTNAME + @"").Replace(@" ", @"")
== @"FOLLOWTO"
)
).FirstOrDefault();
Code returns correct contact on my sample data:
foreach (CONTACT n in db.CONTACTs.Where(n => n.ACCOUNTID == account.ACCOUNTID))
{
string ContactName = (n.FIRSTNAME + n.MIDDLENAME + n.LASTNAME + @"")
.Replace(@" ", @"");
if (ContactName == @"TOFOLLOW" || ContactName == @"FOLLOWTO")
to_follows_contact = n;
}
@signs for C# verbatim strings are not necessary in this case.