Browsing 7239 questions and answers with Jon Skeet

add JSONArray within a JSONObject

I'm making an application to send notifications using OneSignal and must do a POST request in JSON format. To send notification to a user I have to use the include_player_ids...
Jon Skeet
people
quotationmark

I believe the problem is that you're using org.json.alt.JSONArray instead of org.json.JSONArray. I'm not familiar with that class, but I suspect JSONObject.put is just calling toString() on it rather than treating it as an existing JSON... more 5/11/2018 3:48:02 PM

people

Determine which part of an interval overlaps a given weekday in a given time zone

I have a global time interval (from one UTC "time stamp" to another) and want to determine which part of the interval overlaps a given week day in a given time zone. Let's take...
Jon Skeet
people
quotationmark

There are a few issues in the tests, but after changing those a little, they pass with the code below. In principle, it's a matter of: Take the interval, and work out the dates that might be within it for any time zone. We can just... more 5/11/2018 9:34:14 AM

people

DateTime + TZ > NodaTime conversion

When I look about how to convert time to NodaTime, I find many posts but not a single straight answer about what I need. I have: - A DateTime object (DateTime myDateTime) - An...
Jon Skeet
people
quotationmark

It sounds like you just want: var local = LocalDateTime.FromDateTime(myDateTime); var zone = DateTimeZoneProviders.Tzdb[id]; var zoned = local.InZoneLeniently(zone); Except: You may well want to write your own rules instead of using... more 4/26/2018 5:12:38 PM

people

Unlimited method arguments without GC

I am trying to make a function that can receive unlimited amount of arguments without crating GC. I know that this can be done with the params keyword but it creates GC. Also...
Jon Skeet
people
quotationmark

If you use params and specify arguments in that way then yes, it will always create an array object. If you want to avoid that, and if you don't need to worry about recursion or thread safety, you could keep a List<GameObject>... more 4/21/2018 7:45:11 AM

people

Checking if a string contains a regex in the form of a date in c#

I have a string variable defined as : string str = Request[columns[2][search]]; Sometimes the str returns me a value of AR and sometimes 15/02/2018 to 23/04/2018 Therefore I...
Jon Skeet
people
quotationmark

I would do this in two passes: Use a regular expression to extract the dates if they're present at all. Use DateTime.TryParseExact to check that each date really is a date. I would recommend against trying to do full date validation in... more 4/21/2018 7:18:12 AM

people

how does a Dictionary find an object after a GC?

looking at this post: references updated on GC, it seems that the heap could get compacted on a Garbage collection which means that the references would change. Now if I were to...
Jon Skeet
people
quotationmark

The dictionary doesn't use the object's location in memory to do book-keeping - it uses the hash code. The hash code of an object doesn't change when the object is moved in memory, even if it doesn't override GetHashCode(). The details... more 4/21/2018 6:47:27 AM

people

Using StringBuilder.Append() in a lambda expression is producing an empty string

I'm trying to append a list of strings( 10),so to avoid creating a lot of strings I am using a StringBuilder.It would be great if someone explains why this is happening.. using...
Jon Skeet
people
quotationmark

As has been noted in other answers, the laziness of Select is the problem here. I'd add that more broadly, using side-effects (such as appending to a StringBuilder) is generally a bad idea within a LINQ query. Each selector, condition etc... more 4/12/2018 6:32:01 AM

people

Using Service User to upload files to Google Drive by email address

I am connecting to a service account using a service account credential. I'm trying to scale this up to be used for multiple users within the same company. All users will have...
Jon Skeet
people
quotationmark

You want to use ServiceAccountCredential, with a User property set to the appropriate user. Assuming you're loading the credentials using GoogleCredential, this isn't too hard. For example: GoogleCredential credential =... more 4/3/2018 3:08:59 PM

people

Hot to logic compare a bool array with itself for a single bool result?

I have an array that looks like this: bool[] array = new bool[4] { true, false, true, true } ; And I'd like to do an AND/OR comparison between all the elements of this array,...
Jon Skeet
people
quotationmark

As per comments and other answers, you can use LINQ for both of these. (Although you don't have to; farbiondriven's answer will work absolutely fine, although it's less general purpose in that LINQ solutions can handle any... more 4/3/2018 2:04:51 PM

people

What is the difference between WithIsoIntervalConverter() and WithIsoDateIntervalConverter()?

I have recently began using NodaTime, and wanted to use the JSON.NET serializer settings which come with it. There is however one thing I do not understand and fail to find in the...
Jon Skeet
people
quotationmark

WithIsoIntervalConverter replaces the converter for the Interval type. WithIsoDateIntervalConverter replaces the converter for the DateInterval type. If you're not using Interval or DateInterval, you won't care what the converter does... more 4/2/2018 3:15:30 PM

people