I’m trying to create a MailMessage, and I’m getting the following error…
Cannot implicitly convert type 'string' to 'bool'
This is my init statement:
MailMessage msg = new MailMessage("DoNotReply@optoma.com",
myTbl.Rows[i]["Requester"].ToString().Trim(),
subject,
"Dear " + myTbl.Rows[i]["Ship_Attention"].ToString() + ",<br/><br/>" +
body + "<br/>Your ISO ID is " + myTbl.Rows[i]["ISO_ID"].ToString() +
(Convert.ToInt32(myTbl.Rows[i]["EmailType"]) == 1) ?
("<br/>Tracking Number: " + myTbl.Rows[i]["Tracking_No"].ToString()) :
("") + "<br/><br/>Please examine the loaned items for this transaction:<br/><br/>" +
sw.ToString());
I’m trying to add to the string at runtime based on a boolean expression. Why can’t I do this? Am I not doing it right?
string + (true | false) ? "somestring" : "anotherstring" + string
the ? : operator has very low precedence. Put it in parenthesis and I think you’ll resolve your issue.