tostring

Overriding ToString() for debugging and logs - should the string be localized?

ε祈祈猫儿з 提交于 2019-12-10 03:21:11
问题 I'm designing a .NET library that will be used by other developers making both web and desktop applications. I'm overriding ToString() in various classes to provide information for debugging purposes and for inclusion in application log files. Some of my classes contain numbers and dates. Consider an object that contains a DateTime called date and a double called value (and maybe other fields as well)... If I override that object's ToString() , I might want to do something like: public

JPA: java.lang.StackOverflowError on adding toString method in entity classes

狂风中的少年 提交于 2019-12-09 18:01:34
问题 Everything worked fine until I added toSting() in my entity classes. After which I start getting the following error in runtime: Exception in thread "main" java.lang.StackOverflowError at java.lang.AbstractStringBuilder.append(Unknown Source) at java.lang.StringBuilder.append(Unknown Source) at java.lang.StringBuilder.<init>(Unknown Source) at entity.Guide.toString(Guide.java:51) at java.lang.String.valueOf(Unknown Source) at java.lang.StringBuilder.append(Unknown Source) at entity.Student

Why does Boolean primitive not call prototype toString()?

╄→尐↘猪︶ㄣ 提交于 2019-12-09 15:27:19
问题 Say I have this code: Boolean.prototype.toString = function toString() { return this.valueOf() ? '1' : '0'; }; var object = { true: 'true', false: 'false', 1: '1', 0: '0' }; // "true" - this doesn't work console.log('primitive', object[true]); // "1" - but these do console.log('primitive.toString()', object[true.toString()]); console.log('instance', object[new Boolean(true)]); Why doesn't the primitive use the class's toString definition? Object keys are either strings or symbols, they cannot

Why does .NET decimal.ToString(string) round away from zero, apparently inconsistent with the language spec?

喜夏-厌秋 提交于 2019-12-09 14:14:30
问题 I see that, in C#, rounding a decimal , by default, uses MidpointRounding.ToEven . This is expected, and is what the C# spec dictates. However, given the following: A decimal dVal A format string sFmt that, when passed in to dVal.ToString(sFmt) , will result in a string containing a rounded version of dVal ...it is apparent that decimal.ToString(string) returns a value rounded using MidpointRounding.AwayFromZero . This would appear to be a direct contradiction of the C# spec. My question is

Type overloading macro

我怕爱的太早我们不能终老 提交于 2019-12-09 12:15:52
问题 I have a bunch of printf debug helper macros and it would be pretty cool to have to not specify the type, is there anything you can do to allow something like macro overloading in c(can be gcc specific if its available in gcc 4.3). I thought maybe typeof but apparently that doesn't work. example macro(I also have some ascii terminal color stuff that I can't remember of the top of my head) #ifdef _DEBUG #define DPRINT_INT(x) printf("int %s is equal to %i at line %i",#x,x,__LINE__); . . . #else

toString Method Call in Java [duplicate]

孤街醉人 提交于 2019-12-09 07:21:53
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Why is the toString() method being called when I print an object? I have this piece of code below. I understand everything else except the output using the toString method in the Room Class . In the HotelMain Class, I just called the displayRooms Method that was in the Hotel Class . But, when I ran the program, the toString output was shown in the console. If I'm right toString() is the textual representation of

Using StatePrinter from VB rather than C# to implement ToString

懵懂的女人 提交于 2019-12-09 04:04:27
I'm trying to follow the promising suggestion posted here to try StatePrinter as a shortcut to rolling my own ToString methods. I agree with the OP that it is a shame that VS still can't generate this method for me. I've got a fairly large project, in VS2015 (Community Edition), with both VB and C# code. I added the current stable version of StatePrinter using NuGet. I can make the example code from the SO answer work fine in my C# code but when I do what I think is the equivalent in my VB code: Private Shared sp As StatePrinter.Stateprinter = New StatePrinter.Stateprinter Public Overrides

decimal ToString formatting which gives at least 1 digit, no upper limit

只愿长相守 提交于 2019-12-08 20:33:37
问题 How to format a decimal in C# with at least one digit after the decimal point, but not a fixed upper limit if specified more than 1 digit after the decimal point: 5 -> "5.0" 5.1 -> "5.1" 5.122 -> "5.122" 10.235544545 -> "10.235544545" 回答1: Use ToString("0.0###########################"). Some notes:, There are 27 # s in there, as the decimal structure can accommodate precision up to 28 decimal places. The 0 custom specifier will cause a digit to always be displayed, even if the value is 0. The

Override Object.toString Error

橙三吉。 提交于 2019-12-08 18:33:30
问题 Why does this produce an error in Flash Builder?: package { public class Foo { override public function toString():String { return "Foo"; } } } Tab completion suggests that this is available for override... Error message: Multiple markers at this line: -public -1020: Method marked override must override another method. -overridesObject.toString 回答1: Remove override on the toString() method. There is a popular misconception among about the toString() method, namely: if one wants to provide a

C#: How should ToString() be implemented? [closed]

一世执手 提交于 2019-12-08 17:26:35
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . The problems are: GUI libraries like to use ToString as a default representation for classes. There it needs to be localized. ToString is used for logging. There it should provide programming related information, is not translated and includes internal states like surrogate