Why is a round-trip conversion via a string not safe for a double?

Recently I have had to serialize a double into text, and then get it back. The value seems to not be equivalent: double d1 = 0.84551240822557006; string s = d1.ToString(“R”); double d2 = double.Parse(s); bool s1 = d1 == d2; // -> s1 is False But according to MSDN: Standard Numeric Format Strings, the “R” … Read more

Problem with converting int to string in Linq to entities

var items = from c in contacts select new ListItem { Value = c.ContactId, //Cannot implicitly convert type ‘int’ (ContactId) to ‘string’ (Value). Text = c.Name }; var items = from c in contacts select new ListItem { Value = c.ContactId.ToString(), //Throws exception: ToString is not supported in linq to entities. Text = c.Name }; … Read more

How do I print my Java object without getting “SomeType@2f92e0f4”?

I have a class defined as follows: public class Person { private String name; // constructor and getter/setter omitted } I tried to print an instance of my class: System.out.println(myPerson); but I got the following output: com.foo.Person@2f92e0f4. A similar thing happened when I tried to print an array of Person objects: Person[] people = //… … Read more

Printing out a linked list using toString

public static void main(String[] args) { LinkedList list = new LinkedList(); list.insertFront(1); list.insertFront(2); list.insertFront(3); System.out.println(list.toString()); } String toString() { String result = “”; LinkedListNode current = head; while(current.getNext() != null){ result += current.getData(); if(current.getNext() != null){ result += “, “; } current = current.getNext(); } return “List: ” + result; }