FormatException when passing DateTime.toString() to AppendFormat C# .NET -
i'm trying following:
var policybuilder = new stringbuilder(); var expiration = datetime.utcnow.adddays(1).tostring("s") + "z"; policybuilder.appendformat("{ \"expiration\": \"{0}\",\n", expiration);
however, last line throws following exception:
exception of type 'system.formatexception' occurred in mscorlib.dll not handled in user code additional information: input string not in correct format.
'expiration' string, why getting error?
thanks
if want {
@ beginning have use two:
policybuilder.appendformat("{{ \"expiration\": \"{0}\",\n", 10);
see: escaping braces in composite formatting
opening , closing braces interpreted starting , ending format item. consequently, must use escape sequence display literal opening brace or closing brace. specify 2 opening braces ("{{") in fixed text display 1 opening brace ("{"), or 2 closing braces ("}}") display 1 closing brace ("}"). braces in format item interpreted sequentially in order encountered. interpreting nested braces not supported. ....
Comments
Post a Comment