Browsing 7239 questions and answers with Jon Skeet

Implementing correct GetHashCode

I have the following class public class ResourceInfo { public string Id { get; set; } public string Url { get; set; } } which contains information about some...
Jon Skeet
people
quotationmark

Your approach to equality fundamentally breaks the specifications in Object.Equals. In particular, consider: var x = new ResourceInfo { Id = null, Uri = "a" }; var y = new ResourceInfo { Id = "yz", Uri = "a" }; var z = new ResourceInfo {... more 7/14/2014 9:08:44 AM

people

Different MD5 results

I am porting an application developed in Java struts to PHP, the database is in MySQL, The PHP, MySQL or online MD5 produces this for NtbPq...
Jon Skeet
people
quotationmark

I strongly suspect that the hex conversion you're using in the application is failing if the leading nybble of a byte is 0. This is probably because you've got hex conversion code within the application itself, rather than using a standard... more 7/14/2014 8:25:36 AM

people

Call abstract method from class constructor

I have base class that contain abstract method. public abstract class ClassBase : IClassBase { protected ClassBase() { //// some code } protected...
Jon Skeet
people
quotationmark

It's unclear exactly what code you meant, as the code you've given doesn't compile for a couple of reasons. Most importantly, did you actually mean to call Init from ClassBase rather than from Class_A? If not, it seems pointless making... more 7/14/2014 6:47:46 AM

people

How to compare two times in java?

I am developing a app for sync contacts. Every contact have a update_time field. I want to compare this current update_time to previous update_time. My problem is I am storing...
Jon Skeet
people
quotationmark

(You may want to consider storing the values in your database as integers instead of as text. There are pros and cons here, so I'll just leave that as a thought which is somewhat separate to your actual question.) The parsing is... more 7/13/2014 8:11:43 PM

people

How can I add two variables in a java subclass to pass as one variable to the superclass?

I'm just learning Java, and I have a question. I'm not sure that I'm using the correct terminology, so please correct me if necessary. I'm curious if there is a better way to add...
Jon Skeet
people
quotationmark

You can't access fields before you call the superclass constructor - basically the very first thing that any constructor does is invoke a superclass constructor. The only thing you get to do is evaluate arguments to call that superclass... more 7/13/2014 7:53:44 PM

people

tostring() is implicitly called... how?

In the following code, how is toString() is implicitly called? class Payload { private int weight; public Payload (int w) { weight = w; } public void...
Jon Skeet
people
quotationmark

This line: System.out.println("p is " + p); uses string concatenation, which is specified in section 15.18.1 of the JLS, starting with: If only one operand expression is of type String, then string conversion (ยง5.1.11) is performed... more 7/13/2014 7:10:42 AM

people

Parse a UTC date string to date in C#

Simple question, I have this string: string dateString = "7/12/2014 4:42:00 PM"; This is a date string and it's in the UTC timezone. I need to convert it to a date, so I'm...
Jon Skeet
people
quotationmark

how can I tell him that the date string provided is in the UTC format and not in the local timezone format? Specify a DateTimeStyles value of AssumeUniversal in the call. That tells the parsing code what to do. For example: // null... more 7/12/2014 5:39:27 PM

people

Cast to Func vs new Func?

Is there any difference between the following two statement? They both work. if ( ((Func<bool>)(()=>true))() ) { .... }; if ( new Func<bool>(()=>true)()) {...
Jon Skeet
people
quotationmark

No, they both compile to exactly the same IL. It's easier to see if you actually give the lambda body something that depends on state - otherwise the compiler caches a single delegate instance for each lambda. But for example: using... more 7/11/2014 8:24:59 PM

people

Returning a value from a method within a lambda expression

I'm trying to figure out how to return a method value from a lambda expression: public int findMissingNumber(Collection<Integer> ints) { Single<Integer> start =...
Jon Skeet
people
quotationmark

Is there some type of way to break or force a return for the entire method? No. At least, not unless you throw an exception. Basically, that's not what forEach is meant for. You could write a method which accepted a function which... more 7/11/2014 7:09:40 PM

people

How to remove an specific xml attribute from org.w3c.dom.Document

I have this XML: <Body xmlns:wsu="http://mynamespace"> <Ticket xmlns="http://othernamespace"> <Customer xlmns="">Robert</Customer> ...
Jon Skeet
people
quotationmark

You need to understand that xmlns is a very special attribute. Basically, the xmlns="" is so that your Customer element is in the "unnamed" namespace, rather than the http://othernamespace namespace (and likewise for other elements which... more 7/11/2014 1:53:51 PM

people