C#: Overriding ToString() method for custom exceptions

This is all overkill. Your exception should just override the Message Property. public override String Message { get { return base.Message + String.Format(“, HttpStatusCode={0}, RequestId='{1}'”, httpStatusCode, RequestId); } } The default ToString method for the Exception class is basically “ClassName: Message –> InnerException.ToString() StackTrace“. So overriding the Message puts your message text exactly where it … Read more

How to make JSON.Net serializer to call ToString() when serializing a particular type?

You can do this easily with a custom JsonConverter: public class ToStringJsonConverter : JsonConverter { public override bool CanConvert(Type objectType) { return true; } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteValue(value.ToString()); } public override bool CanRead { get { return false; } } public override object ReadJson(JsonReader reader, Type objectType, object … Read more

Why does the toString method in java not seem to work for an array

To get a human-readable toString(), you must use Arrays.toString(), like this: System.out.println(Arrays.toString(Array)); Java’s toString() for an array is to print [, followed by a character representing the type of the array’s elements (in your case C for char), followed by @ then the “identity hash code” of the array (think of it like you would … Read more

How convert TimeSpan to 24 hours and minutes String?

myTimeSpan.ToString(@”hh\:mm”) Custom TimeSpan Format Strings The custom TimeSpan format specifiers do not include placeholder separator symbols, such as the symbols that separate days from hours, hours from minutes, or seconds from fractional seconds. Instead, these symbols must be included in the custom format string as string literals. For example, “dd.hh\:mm” defines a period (.) as … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)