What are the shortcut to Auto-generating toString Method in Eclipse?

Eclipse 3.5.2 (and possibly earlier versions) already provides this feature. If you right-click within the editor, you’ll find it under Source -> Generate toString()… To answer your question about whether it’s a bad practice to autogenerate toString(), my opinion is that it is not. If the generated code is very similar to the code you … Read more

Overriding ToString() of List

Perhaps a bit off-topic, but I use a ToDelimitedString extension method which works for any IEnumerable<T>. You can (optionally) specify the delimiter to use and a delegate to perform a custom string conversion for each element: // if you’ve already overridden ToString in your MyClass object… Console.WriteLine(list.ToDelimitedString()); // if you don’t have a custom ToString … Read more

C# Converting 20 digit precision double to string and back again

Use the “R” numeric format string: double d = 0.00034101243963859839; string s = d.ToString(“R”); //… double d2 = double.Parse(s); if(d == d2) { //– Success } The R stands for “round-trip”. From the linked document: This format is supported only for the Single and Double types. The round-trip specifier guarantees that a numeric value converted … Read more

Lua – Number to string behaviour

In Lua 5.2 or earlier, both tostring(10) and tostring(10.0) result as the string “10”. In Lua 5.3, this has changed: print(tostring(10)) — “10” print(tostring(10.0)) — “10.0” That’s because Lua 5.3 introduced the integer subtype. From Changes in the Language: The conversion of a float to a string now adds a .0 suffix to the result … Read more

Converting Range or DocumentFragment to string

So, how to get the string of the html of a Range or DocFrag? Contrary to the other responses, it is possible to directly turn a DocumentFragment object into a DOMString using the XMLSerializer.prototype.serializeToString method described at https://w3c.github.io/DOM-Parsing/#the-xmlserializer-interface. To get the DOMString of a Range object, simply convert it to a DocumentFragment using either of … Read more

tech