Browsing 7239 questions and answers with Jon Skeet

Java 8 ZonedDateTime

I am trying to use ZonedDateTime.now(ZoneOffset.UTC).toString() to get the current time. It works well, but seems to cut off seconds / milliseconds when they are right on a...
Jon Skeet
people
quotationmark

Firstly, it sounds like you really want an Instant rather than a ZonedDateTime - that takes the time zone part out of the picture entirely. But either way, just use a DateTimeFormatter to format the value however you want. It sounds like... more 6/16/2016 5:54:42 AM

people

Thread.join() and synchronization?

Is Thread.join() a full synchronization with flushing of caches etc. when performed of the thread beeing joined?
Jon Skeet
people
quotationmark

I think you're asking whether from thread T1 that calls join on T2, code in T1 reading data after the join() will definitely see changes written by T2. If that's the case, then the answer is yes, due to JLS 17.4.4: The final action in... more 6/15/2016 3:04:12 PM

people

concrete implemantation of IEnumerable<T> that is not ICollection<T>

I would like to know if any of the classes in the .net framework that implement IEnumerable doesn't implement the ICollection interface. I'm asking it because I can't get 100%...
Jon Skeet
people
quotationmark

Just use any LINQ operation, e.g. Where: [Test] public void GetSafeCount_NonICollectionObject_ReturnCount() { IEnumerable<string> enumerable = new string[0].Where(x => x.Length == 0); Assert.AreEqual(0,... more 6/15/2016 11:26:14 AM

people

.NET Noda Time Converting Local DateTime To UTC for a specific Timezone

I am using Noda Time to convert local datetime to UTC. This is what I have so far: static string LocalTimeToUTC(string timeZone, string localDateTime) { var pattern =...
Jon Skeet
people
quotationmark

You're missing an hour because there are two UTC instants which both correspond to the same local time, due to the clock going back. The only way of avoiding "missing hours" is to emit two entries for the ambiguous local time. Let's look... more 6/14/2016 3:40:36 PM

people

Enumerable.Concat not working

Below is the code: string[] values = Acode.Split(','); IEnumerable<Test> tst = null; foreach (string a in values) { if (tst== null) tst =...
Jon Skeet
people
quotationmark

Concat doesn't modify anything - it returns a new sequence, which you're currently ignoring. However, rather than using Concat, you should just use SelectMany to flatten the sequence: string[] values = Acode.Split(','); return... more 6/14/2016 3:20:54 PM

people

Lists elements are overwritten while adding a list to a list

I have the following code: Dim innerList As New List(Of String) Dim outerList As New List(Of List(Of String)) For Each ds As datasource In datasources selectedIdentifier =...
Jon Skeet
people
quotationmark

You're creating a single list for innerList, and adding that reference to outerList on each iteration... so your outerList ends up containing lots of references to the same list, which ends up empty because you clear it. You should create... more 6/14/2016 2:59:23 PM

people

Can other methods be called after finalize()?

If I have public class Foo { private boolean finalized = false; public void foo() { if (finalized) throw new IllegalStateException("finalize() has...
Jon Skeet
people
quotationmark

It's entirely possible that a different object which had a reference to the instance of Foo is being finalized at the same time - and may resurrect the Foo object, allowing it to be used after finalization. This is kinda rude, but can... more 6/13/2016 6:40:07 PM

people

Build error: Reference PresentationCore could not be resolved

I have a WPF C# application hosted on GitHub attached to Travis. I configured my .travis-ci.yml this way: language: csharp solution: FaceDetection/FaceDetection.sln script: ...
Jon Skeet
people
quotationmark

Basically, WPF isn't supported by Mono (or .NET running on any platform other than Windows). You'll need to find a Windows-based CI service such as AppVeyor instead. more 6/13/2016 8:10:57 AM

people

Does ConfigureAwait affect non threadpool threads only?

I am playing a little bit with ConfigureAwait because I would like to understand how it works. Therfore, I wrote the following small console application (actually running in...
Jon Skeet
people
quotationmark

The 2. awaitbale task was executed with option "continue on captured context" so I would expect that it runs on the same thread as the code that called it. That assumes that "context == thread", but it doesn't. The synchronization... more 6/12/2016 11:59:58 AM

people

Basic while loop c#

I have problem to work out in which 2 hypothetical oppenents are dueling RPG style. I am asked to give them HP and each round of the loop HP is lost respectiviely to what their...
Jon Skeet
people
quotationmark

You're declaring new variables inside the loop: int fightOneHpLoss = fighterOneHealth - fTwoRandomHit; int fightTwoHpLoss = fighterTwoHealth - fOneRandomHit; ... but you're never modifying the variables which are meant to represent the... more 6/11/2016 6:48:28 AM

people