Browsing 7239 questions and answers with Jon Skeet

JSON is valid, but result in code returns null

I have this simple JSON { "persons": [{ "firstname": "Brad", "lastname": "Pitt" }, { "firstname": "George", "lastname": "Clooney" },...
Jon Skeet
people
quotationmark

Your data doesn't contain a List<PersonObject> - it contains a single PersonObject which in turn contains a List<Person>. So this works fine: var json = File.ReadAllText("test.json"); var obj =... more 9/15/2016 9:56:41 AM

people

.NET Decimal.Parse throws a FormatException when using period as thousand separator

In .NET, can anyone tell me why this works: Decimal.Parse("1,234.56", CultureInfo.GetCultureInfo("en-US")); But this throws a System.FormatException? Decimal.Parse("1.234,56",...
Jon Skeet
people
quotationmark

The French CultureInfo's NumberFormatInfo uses space as the NumberGroupSeparator - so this works, for example: Decimal.Parse("1 234,56", CultureInfo.GetCultureInfo("fr-FR")); If you want to use . as a thousands separator, you'll need a... more 9/15/2016 9:26:07 AM

people

String interpolation on the result of a function that returns string

I have a function which gets some text from an xml file like this: var text = Translate("/foo/bar"); Now in the XML I want to put in string interpolation constants like...
Jon Skeet
people
quotationmark

No, you can't do this. String interpolation is performed at compile-time. The compiler examines the interpolated string literal, finds the relevant format strings and converts them to {0} etc. There's nothing similar to perform this at... more 9/15/2016 8:55:00 AM

people

What is the point of using EventHandler like that?

What is the use of unregistering event handler that is not added yet in the code below? public class foo { private event EventHandler<boo> booCompleted; public...
Jon Skeet
people
quotationmark

It means that if you call RegisterBooCompletedHandler(handler) multiple times with the same handler, you still only actually subscribe to the event once for that handler. My guess is that actually you've seen this due to someone working... more 9/14/2016 6:08:09 AM

people

Get TZ abbrev for given timestamp and TZ name

Is it possible to get correct TZ abbreviation after converting column of type timestamptz ? What I am after, sof example, is to display "2016-06-16 16:00:00-04" in "US/Pacific"...
Jon Skeet
people
quotationmark

No, because timestamptz (aka timestamp with time zone) isn't really a timestamp with a time zone, in terms of what's stored... you provide a timestamp and a time zone, and internally it's just stored as a UTC value. It sounds like... more 9/13/2016 2:19:17 PM

people

Don't understand PostgreSQL's time zone behaviour

My local time zone is PRC (china), which is UTC+8, but select (timestamp '2016-09-01 00:00:00' at time zone 'PRC') - (timestamp '2016-09-01 00:00:00' at time zone...
Jon Skeet
people
quotationmark

No, it's doing the right thing - but you have to understand what at time zone means when you provide it with an expression without a time zone as the left hand side. It's basically interpreting it as a timestamp in the specified time... more 9/13/2016 8:34:41 AM

people

Add objects to a List nested inside a Dictionary using LINQ extensions

I have Dictionary<T, T> that contains a key (that represents a category) with an empty List<T> as value: Dictionary<string, List<IMyObject>>...
Jon Skeet
people
quotationmark

I would suggest using a lookup instead: ILookup<string, IMyObject> lookup = myObjectsUnsorted.ToLookup(t => t.Category); ILookup<,> is precisely designed to be a "multiple values per key" dictionary. As well as being... more 9/13/2016 7:26:24 AM

people

Git for visual studio 2015, delete intermediate commit

Im new using GIT...While working with it, i have created intermediate commits just in the case my computer crash or something like that, so i have a commit history like this in a...
Jon Skeet
people
quotationmark

Rebase is your friend here: git rebase -i HEAD~4 Replace the second to fourth lines starting with "pick" to "f" for "fixup", and you'll end up with a single commit. more 9/12/2016 8:23:06 PM

people

Strange Java behaviour with static and final qualifiers

In our team we found some strange behaviour where we used both static and final qualifiers. This is our test class: public class Test { public static final Test me = new...
Jon Skeet
people
quotationmark

S is a compile-time constant, following the rules of JLS 15.28. So any occurrence of S in the code is replaced with the value which is known at compile-time. If you change the type of I to int, you'll see the same for that, too. more 9/12/2016 10:25:51 AM

people

Attempting to loop through a list of direct download links; first file downloads but second gets stuck at 0 bytes and never finishes (C#)

I'm attempting to run through a list of direct download links using the code below. The code runs and downloads the first file just fine, as it moves to the second file (second...
Jon Skeet
people
quotationmark

I suspect the problem is this line: w.OpenRead(s); That's returning a Stream that you never close. Now you could just close it... but it would be better to use it, and not bother with the DownloadFile call: using (Stream responseStream... more 9/12/2016 10:22:21 AM

people