Browsing 15589 questions and answers with Jon Skeet

TimeZoneInfo AdjustmentRule error on .net core 1.1

I have a piece of code that allows me to get the current date/time (local). It will be run on Azure. I'm getting universal time and converting it to local UK time (taking into...
Jon Skeet
people
quotationmark

You shouldn't need to do any of this yourself - just ask TimeZoneInfo to do the conversion. That's what it's there for! // Only need to do this once... private static readonly TimeZoneInfo londonZone = ... more 4/5/2017 9:34:40 PM

people

ConcurrentQueue c#, inexact result?

I would like to ask about queue in c# If ConcurrentQueue is safe thread, why the result of this code is ~98 k? Do I something wrong? class Program { static int sum = 0; ...
Jon Skeet
people
quotationmark

This is the problem: sum += result; That's not atomic. It's effectively: var tmp = sum; tmp += result; sum = tmp; What do you think will happen if both of your threads reach the middle line at the same time? You can fix this with... more 4/4/2017 7:13:03 PM

people

Java Preparedstatement error when reading from MySql Database

I'm working on a simple application that pulls data from a local database. The below code works fine when I use a string for the SQL query, but I can not get it to work with...
Jon Skeet
people
quotationmark

Parameters in prepared statements are for values - you're trying to use them to select fields. They just don't work that way. In this very specific instance, you'll need to make the SQL dynamic. However, you'll want to make sure that... more 4/4/2017 3:11:45 PM

people

ะก# Json to custom class

I have json : [ { "Name" : "SHA of timestamp", "ProjectURL" : "URL to Proj", "AccountIdentifier" : "Account Identifier", "Repositories": ...
Jon Skeet
people
quotationmark

It looks like you probably shouldn't have a Repositories class - instead, change your ConfigEntry.Repositories property to: public Dictionary<string, Git> Repositories { get; set; } Then you'll get a dictionary where the key of... more 4/3/2017 9:38:55 AM

people

C# Google Sheets APIv4 filling requestbody

Sorry if this question is very basic. I'm trying to create an update request to fill me some googledocs spreadsheets with content (btw the portion of the code that READS those...
Jon Skeet
people
quotationmark

Basically, requestBody.Values will be null until you populate it. Just create your own list and populate it with your array, e.g. var test = new string[] { "p1", "p2", "p3", "", "", "", "", "foo" }; requestBody.Values = new... more 4/1/2017 12:37:39 PM

people

instanceOf operator in java

Why is this line of code in Java not printing the message? System.out.println("a instanceof String:"+a instanceof String); Why is it just printing true and not the String...
Jon Skeet
people
quotationmark

Ah, the joys of operator precedence. That line is effectively: System.out.println(("a instanceof String:" + a) instanceof String); ... so you're doing string concatenation, and then checking whether the result is a string. So it will... more 4/1/2017 11:42:30 AM

people

C# Array.Resize Passing a Ref instead of a Value

Title might be a bit misleading I have a string array. That I would like to pass by reference. I know it can be accomplished simply by public class test{ string[] content =...
Jon Skeet
people
quotationmark

How do I prevent the reference to the main array from breaking when the need arises for me to resize it? You don't. You just don't use an array. Array objects aren't resizable, and after you've copied the value of contentToShow into... more 3/31/2017 10:14:51 AM

people

Do C# properties always have backup fields "behind the scene"?

I know that when we use properties in C#, the compiler always generate getters and setters for them in MSIL (i.e., get_PropertyName and set_PropertyName), for example, consider...
Jon Skeet
people
quotationmark

But since I don't know how to check it, can you please let me know if a backup field always get created (even if we have a simple property with only get; and set; ? An automatically implemented property, e.g. public int... more 3/30/2017 8:15:30 AM

people

Reference a .NET Standard 1.6 library from a .net 4.6.2 library

I have a home grown nuget package that targets netstandard1.6 published to a private feed. When I try to install it into a package that targets .NET Framework 4.6.2, nuget tells...
Jon Skeet
people
quotationmark

The plan is that this will work with netstandard2.0 tooling, I believe - but it doesn't work at the moment due to some oddities around net46x. There are two docs for the mappings between netstandard and .NET framework... more 3/30/2017 6:17:29 AM

people

C# Method parameter incorrectly updates

I have the following C# simple code : public class Error { public string ErrorDescription { get; set; } public string ErrorCode { get; set; } } public class Request { ...
Jon Skeet
people
quotationmark

This is the start of the problem: ResponseError = request.RequestError; You have a single Error object - after that line, your response and request both refer to the same object. Bear in mind that Error is a class, so the values of... more 3/28/2017 3:56:34 PM

people