Browsing 7239 questions and answers with Jon Skeet

Missing Microsoft time zones

I'm looking at using the Microsoft time zones (by utilising the System.TimeZoneInfo class in C#) to convert stored UTC dates to local timezone dates and vice versa. However,...
Jon Skeet
people
quotationmark

The conversion data between Windows time zone IDs and IANA time zone IDs is available via CLDR. Looking at the data (and at the raw IANA data in Github) it looks like the IANA time zones in question are: "America/Godthab" (West... more 4/1/2018 4:33:01 PM

people

Constraint for classes defined inside a static class

Hello is there any way to constrain a generic method for classes which are defined inside a static class? static class Container { class A { } class B { ...
Jon Skeet
people
quotationmark

Is there any way to constrain a generic method for classes which are defined inside a static class? No, there isn't. The only type constraints are: Requiring a public parameterless constructor (where T : new()) Requiring it to be a... more 3/30/2018 9:07:52 AM

people

Java, is it possible to create global variable for thread

In Java 6, is there some sort of thread-bounded context, where I can store and retrieve objects at runtime in the current thread at any code location? I would need this for...
Jon Skeet
people
quotationmark

It sounds like you're looking for ThreadLocal<T>, but I'd generally be careful about using this - it can lead to code where the interaction between two classes is hard to reason about, and it limits how you work with threads later... more 3/29/2018 10:44:56 AM

people

C# DateTime ToString Standard culture format

Can I alter the standard output format of a DateTime for a specific culture. Example: class Program { static void Main(string[] args) { ...
Jon Skeet
people
quotationmark

You can use DateTimeFormatInfo.ShortDatePattern to get the pattern, and then replace d with dd if you really want to. You might need to consider corner cases such as escaped or quoted d patterns though - as well as obviously not replacing... more 3/27/2018 2:25:54 PM

people

How return the type implemented by the interface

The idea is make ExporParts function in Export Class works with any WebData derivative. To do that I need to know the T type class and it name. The solution proposed works, but I...
Jon Skeet
people
quotationmark

I think you're just looking for a class literal: @Override public Class<BikeModel> GetReturnType() { return BikeModel.class; } more 3/27/2018 11:47:50 AM

people

Google Sheets use API key instead of client_secret.json

In the QuickStart.java example on Java Quickstart they use OAuth client ID to identify the application, and this pops up a windows asking for Google credentials to use the...
Jon Skeet
people
quotationmark

An API key could only work when accessing the resources owned by the project that created the key. For resources like spreadsheets, you're typically accessing resources owned by a user. It would be pretty awful if you got access to my... more 3/27/2018 11:26:28 AM

people

.Where(Date.AddHours) filter doesn't seem to work

I'm sorting a list of files that was created from yesterday 1:00pm to present time. I'm trying to use the following code: The messagebox shows the correct time I'm trying to...
Jon Skeet
people
quotationmark

DateTime.Now.Date.AddDays(-1).AddHours(13) will return 1pm... but you're checking against new FileInfo(file).CreationTime.Date, which is always at midnight... for a file created yesterday, it will be yesterday at midnight. So yes, you're... more 3/27/2018 11:07:58 AM

people

Installing NodaTime 2.2.x in PCL with Profile44

I am working on a PCL project that is using Profile44 as TargetFrameworkProfile. When I try to install NodaTime 2.2.4 I get the following error message: Could not install package...
Jon Skeet
people
quotationmark

Noda Time 2.x only supports the Target Framework Monikers netstandard1.3 and net45. There's no direct PCL support, although some environments that traditionally used PCLs now support .NET Standard. The 1.x series supports PCLs via... more 3/27/2018 5:37:15 AM

people

Why do I have to explicitly specify my type arguments for Func parameters?

I am writing a simple Memoize helper that allows caching method results instead of computing them every time. However, when I try to pass a method into Memoize, the compiler can't...
Jon Skeet
people
quotationmark

Isn't DoIt() signature compatible with Func<string, int>? Yes it is. It's fine to convert it to that specific type, like this for example: Func<string, int> func = DoIt; var cachedDoit = Memoize(func); The problem... more 3/23/2018 9:27:12 AM

people

var array = new [] {d, "hello"} is implicitly typed to dynamic[] and not string[] ? why?

dynamic d = 5; var array = new[] {d,"hello"} What is the implicit type of array ? It is dynamic[] but not string[], why ? While going through C# in depth - Jon Skeet stated a...
Jon Skeet
people
quotationmark

For the most part, you can ignore this detail. But if you look through the specification, you'll see various place that the language considers conversions from type X to type Y. There are other places that the language considers... more 3/23/2018 6:05:28 AM

people