Browsing 15589 questions and answers with Jon Skeet

Comparing two different timezone timespans using NodaTime

I have a requirement which I'm getting a little confused about. I started using NodaTime which I think is the best way to go. I have two users, User1 and User2 both in two...
Jon Skeet
people
quotationmark

Firstly, be aware that it could change each day: don't treat a time zone as a fixed offset. Secondly, be aware that the local time specified (for each of start/end) may not even happen, or may happen twice. Work out how you want to handle... more 3/14/2017 7:42:33 PM

people

How do you share Java functions without giving others source code?

When programming in C++ we have header files and source files. When our company sells our product (which is just a library of useful functions essentially) we provide the client...
Jon Skeet
people
quotationmark

In Java you don't need source code to compile against - the bytecode contains all the metadata you need. So for example, if I create an interface with some methods in, compile it into a class file, then package that up into a jar file and... more 3/14/2017 3:21:26 PM

people

Parse enum skipping Obsolete

How to skip obsolete values when I'm casting my int values to enums? I have minimum working example below: using System; public class Program { public static void Main() ...
Jon Skeet
people
quotationmark

I'm getting ValueA, but expecting to get ValueB. You're getting the value represented by the integer 1. The fact that you're seeing that as ValueA has nothing to do with Parse, and everything to do with ToString. It's really, really... more 3/13/2017 8:03:09 AM

people

Determine if in DST or not — IsInDaylightSavings()

Is there a way to determine if a ZonedDateTime (in the past) is in DST or not?
Jon Skeet
people
quotationmark

Yes, we've actually made this nice and easy - you just need to call ZonedDateTime.IsDaylightSavingTime. This is implemented by: Obtaining the ZoneInterval from the time zone at the instant represented by the ZonedDateTime Obtaining the... more 3/11/2017 1:09:57 PM

people

Does XDocument.Load loads all data into memory?

I must read all first level nodes of the root node of large xml file that looks like the following: <root> <record...
Jon Skeet
people
quotationmark

No, XDocument loads the whole document into memory. Whether it's "safe" to do this or not depends on what size of document you need to be able to handle. If you need to handle XML files that wouldn't fit into memory, you'd want to use... more 3/11/2017 7:47:47 AM

people

Java hexadecimal base double literal

I am studying for java certification. And i'm curious about the java literals. I know it is possible to do something like this: int i = 0xAA; long l = 0xAAL; Also this is...
Jon Skeet
people
quotationmark

It turns out it is possible, although that surprised me. Section 3.10.2 of the JLS gives the structure of floating point literals, including HexadecimalFloatingPointLiteral. public class Test { public static void main(String[] args)... more 3/10/2017 4:21:48 PM

people

Whats the difference between adding a normal subscriber method to an event, and an anonymous event handler?

I'm struggling to understand why it's okay to attach a 'normal' method as a subscriber to a publisher event, and also a delegate. For example... public class Caller { public...
Jon Skeet
people
quotationmark

Sorry if this seems like a silly question but why is it that you can subscribe a 'normal' method (assuming it matches the delegate signiture) to an event, and also an anonymous method as a delegate to an event. You're subscribing a... more 3/10/2017 4:14:56 PM

people

Unrolled Loop works, for loop does not work

I have some behaviour that I do not understand. While the unrolled loop works fine!!! The loop throws IndexOutOfRangeExceptions. Debugging shows that there 0..9 teamButtons and...
Jon Skeet
people
quotationmark

You're capturing the variable i in your lambda expression. When that lambda expression is executed, it will use the "current" value of i - which will always be 9. You want to capture a copy of the variable... which you can do be... more 3/7/2017 1:53:56 PM

people

c# array collater where the output has the same value every other element

This is an extension of something I'm really working on. It is easy enough to do in a loop but I was wondering if I could find a single-code line. This is the input: byte[] x =...
Jon Skeet
people
quotationmark

You were very nearly there - you just need to use SelectMany instead of Select, as for each input element you're creating a sequence of output elements... then you want to flatten that "sequence of sequences" into a single sequence. That's... more 3/7/2017 3:12:11 AM

people

Get runtime getter of interface property

Declarations: interface I { int i { get; set; } } class C : I { public int i { get; set; } } Code: C c = new C(); c.i = 10; PropertyInfo pi1 = c. GetType(). ...
Jon Skeet
people
quotationmark

You can use Type.GetInterfaceMap() to get a mapping between interface members and the implementing members for a specific type. Here's an example: using System; using System.Linq; using System.Threading; interface I { int Value {... more 3/6/2017 11:27:09 PM

people