c# - concatenation issue adding static string to dynamic string -
the following code working fine static value "application1"
.
mailmsg.headers.add("x-smtpapi", "{ \"category\": [ \"application1\" ] }");
but want replace "application1"
dynamic value.
so implemented following code. dtls.category
dynamic value.
string xsmtpcategory = "{\"category\":\""+dtls.category +"\" ] }"; mailmsg.headers.add("x-smtpapi", xsmtpcategory);
but i'm getting error "not in correct format".
how can fix that?
you left out part of syntax after colon:
string xsmtpcategory = "{\"category\": [ \""+dtls.category +"\" ] }";
i suggest using c# 6.0 string interpolation if possible:
mailmsg.headers.add("x-smtpapi", $@"{{ ""category"": [ ""{dtls.category}"" ] }}");
wiki
Comments
Post a Comment