Browsing 7239 questions and answers with Jon Skeet
The "slightly verbose" option seems reasonable to me, and can easily be isolated into a single extension method: // TODO: Come up with a better name :) public static T SingleOrDefaultOnMultiple<T>(this IEnumerable<T>... more 3/11/2014 1:12:19 PM
Rather than explicitly checking for numbers, I would suggest whitelisting characters which are allowed. Would letters with accents be allowed, for example? Both upper and lower case? Punctuation? Once you've worked out your requirements,... more 3/11/2014 11:18:29 AM
The final option seems reasonable to me - and you can avoid the duplication of the final two lines, and even the one that you missed (the DoWork event): public static BackgroundWorker CreateBackgroundWorker (DoWorkEventHandler... more 3/11/2014 10:22:53 AM
The error is telling you that the Malicious constructor can't find a suitable constructor to chain to in its base class (MaliciousSmall). The initial problem is that your derived class constructor implicitly contains this... more 3/11/2014 9:24:55 AM
Why not just divide it by 100 to start with? That will do the rounding (always towards 0) if you start off with an integer: int zone = (input / 100) + 1; There's no need to get into non-integer arithmetic at all here. If the user input... more 3/11/2014 8:54:36 AM
Basically you need to check whether your startTime and endTime are inverted (i.e. if endTime is before startTime). If it is, that must be a "night-time" interval, and you should just treat it as if they were the other way round, and invert... more 3/10/2014 8:17:44 PM
First, stop building SQL like that. It's vulnerable to SQL injection attacks, conversion issues (which is probably the problem here) and it's hard to read. Use parameterized SQL instead: // TODO: Close the statement, e.g. using a... more 3/10/2014 7:29:30 PM
Two options: Don't include the byte order mark in your text at all... instead use an encoding which will automatically include it Include it as a character in your StringBuilder: sb.Append('\uFEFF'); // U+FEFF is the byte-order mark... more 3/10/2014 5:13:09 PM
Just have a Map<Integer, AipType> instead of using values(), and expose access to it via a method: public enum AipType { UNKNOWN(-1), NONE(0), MOD(1), NO_MOD(2); private static final Map<Integer, AipType>... more 3/10/2014 4:22:17 PM
< is a fundamental entity defined in the XML specification itself; é isn't. That's why you're seeing the difference in behaviour. (So I'd expect &, >, ' and " to work too.) See... more 3/10/2014 1:51:35 PM