Browsing 7239 questions and answers with Jon Skeet

c# static class access in extension methods

Whats the difference between matrix.Extension() and ExtensionMethods.Extension(matrix) ?? static void Main(string[] args) { decimal[,] testData = new[,] {{1m, 2m}, {3m,...
Jon Skeet
people
quotationmark

Whats the difference between matrix.Extension() and ExtensionMethods.Extension(matrix)? Nothing whatsoever. The compiler translates the first into the second, effectively. There will be a difference in C# 6, where if you've... more 8/12/2014 1:41:38 PM

people

calculating the difference in months between two dates

In C#/.NET TimeSpan has TotalDays, TotalMinutes, etc. but I can't figure out a formula for total months difference. Variable days per month and leap years keep throwing me off....
Jon Skeet
people
quotationmark

(I realize this is an old question, but...) This is relatively painful to do in pure .NET. I'd recommend my own Noda Time library, which is particularly designed for things like this: LocalDate start = new LocalDate(2009, 10,... more 8/12/2014 12:24:34 PM

people

Finding Decimal In .Element C# XML

I have a problem with my C# API not finding element decimals (returning error) Here's the XML file <CHandlingDataMgr> <HandlingData> <Item...
Jon Skeet
people
quotationmark

You need to be selecting the fThrust element within the inner item, not the outer one - just as you're already doing for HandlingType: Thrust = (decimal?) i.Element("SubHandlingData") .Element("Item") ... more 8/12/2014 10:37:16 AM

people

C# bracket returned null

Tell me please what is different between return null; and return (null); Sometime i'd seen each an examples
Jon Skeet
people
quotationmark

There's no difference in behaviour whatsoever - but the latter is distinctly unidiomatic. I've previously seen it as a sign that the author seems to think that return is a function call, or at least want to treat it as such. (Sometimes... more 8/12/2014 8:42:34 AM

people

Correct format for DateTime.ParseExact

I have the below string which I need to parse to a DateTime: Thu Aug 14 2014 00:00:00 GMT 0100 (GMT Summer Time) I am unsure what format to supply to my DateTime.ParseExact to...
Jon Skeet
people
quotationmark

If the offset is not important, I suggest you just truncate the string after the time. It looks like the format should allow that by finding the first space after position 16 (the start of the time in your example; part way through the... more 8/12/2014 8:18:34 AM

people

Calculate the duration between now and next local time

I need to determine the duration between now and the next occurrance of a local time. Here's what I've got: Duration GetDuration(IClock clock, LocalTime time, DateTimeZone...
Jon Skeet
people
quotationmark

This code is a bit more long-winded than it needs to be - I'd do most of the work in the "local" context, and only convert back to the time zone when you know the LocalDateTime you want to map. var now = clock.Now.InZone(zone); // Change... more 8/12/2014 6:18:32 AM

people

java template formal parameters with Void

I have two entities extending ResponseEntity: public class VoidResponseEntity<Void> extends ResponseEntity<Void> { ... } public class...
Jon Skeet
people
quotationmark

If your method is deciding the response entity type, I suspect your method shouldn't be generic in the first place: public ResponseEntity<?> foo() { if (condition1) { return new InfoResponseEntity<Info>(new... more 8/12/2014 6:06:21 AM

people

Java try finally race condition?

A lot of Java resource usage examples look like this: Resource r = openResource(); try { // use resource } finally { r.close(); } The declaration of r has to be outside...
Jon Skeet
people
quotationmark

what if there's a thread interruption right between the openResource()-call and entering the try-clause? Then the thread won't throw an InterruptedException until it hits some blocking call. That can't happen before it gets into the... more 8/11/2014 8:19:10 PM

people

There is no implicit conversion between null and null

I have this weird piece of code (that will never, ever be used in production code) that produces a weird compilation error and I'd want to know more about this behavior, string...
Jon Skeet
people
quotationmark

What explains this behavior? The C# 5 specification, section 7.14: The second and third operands, x and y, of the ?: operator control the type of the conditional expression. If x has type X and y has type Y then [...] ... more 8/11/2014 6:59:46 PM

people

Date getTime() from Calendar in specific timezone

I have this code below: Date now = CalendarUtils.getCalendar(getDefaultTimeZone()) .getTime(); The CalendarUtils class has the below methods public static...
Jon Skeet
people
quotationmark

I have read how Date returns the Millis from the Epoch but I would expect that it would return the millis from the Epoch of the date I ask from the Calendar. Then your expectation is incorrect - or you're not expressing your... more 8/11/2014 6:12:03 PM

people