Browsing 7239 questions and answers with Jon Skeet

How is base.GetHashCode() implemented for a struct?

I saw this code recently in a struct and I was wondering what base.GetHashCode actually does. public override int GetHashCode() { var hashCode = -592410294; ...
Jon Skeet
people
quotationmark

The coreclr repo has this comment: Action: Our algorithm for returning the hashcode is a little bit complex. We look for the first non-static field and get it's hashcode. If the type has no non-static fields, we return the... more 10/30/2017 7:07:34 AM

people

How do I fix daily Limit Exceeded when using the .NET client for the google translation API?

I am trying to implement a small slackbot thing where I want to leverage the google tranlation API, but I struggle to get it to work. I did manage to run a single request, but...
Jon Skeet
people
quotationmark

Yes, TranslationClient.Create will use the default credentials - but in this case it's almost certainly the case that they're the wrong default credentials, assuming you're running this locally. If you're running this on Google Cloud... more 10/29/2017 12:27:53 PM

people

Why subsignature and unchecked rules work this way on return types when overriding a generic method with a non generic one?

public class Base { <T> List<? extends Number> f1() {return null;} List<? extends Number> f2() {return null;} <T extends Number>...
Jon Skeet
people
quotationmark

Your f1 and f3 overrides aren't generic, despite the original declarations being generic. The compiles allows the return type of the overrides to vary from the original return types as they have the same type erasure (List). I think that... more 10/29/2017 9:01:09 AM

people

Convert US Central Time to different time zones using moment JS

I have a Date Time(Friday, 27 October 2017 4:00:00 AM) in US Central Time zone (CDT). I want to convert this Date Time into different time zones. These are time zones i wanted to...
Jon Skeet
people
quotationmark

The problem isn't with the conversion to the Indian time zone - it's the original parsing of the Chicago time. This: var dateTime = moment.tz("2017-10-27 4:00:00 AM", "America/Chicago"); ... is treated as 4am UTC, and then converted to... more 10/27/2017 9:35:28 AM

people

C# newbie: how to know the meaning of a variable in a lambda expression

I'm new in a company, using C# (I'm used working with other languages), and I just encountered a Lambda expression in the code, so I'm trying to understand how this works, but the...
Jon Skeet
people
quotationmark

When looking at the definition of "digits", I only see the content, but I can't understand why index is indeed the index of the string. It's because of the overload of Where that's being used. index is a parameter in the lambda... more 10/27/2017 8:19:34 AM

people

Different behavior while passing argument through Thread().start() vs lambda expression in C#

I have created one function named printInteger() as static void printInteger(object i) { Console.Write(i + " "); } I am creating 10 threads using a for loop and passing...
Jon Skeet
people
quotationmark

Why the result in First Method and the Second Method is different? Because in the first approach you're passing the value of i to the Thread.Start method as its initial state. That is evaluated at the time you call Start. In the... more 10/27/2017 6:45:10 AM

people

Trouble getting JSON DeserializeObject to work on this class

I am trying to deserialize the following class using Json.Net and receiving the error: Error converting value "abc" to type 'System.UInt16'. Path 'typestr' public class...
Jon Skeet
people
quotationmark

You've provided JSON with a property of typestr which has a string value. You've also got two parts called typestr in your class: A property (type string) A constructor parameter (type ushort) Json.NET could use either of those, but... more 10/26/2017 9:32:02 PM

people

Javascript New Date() returns invalid date

I have an Array with date strings formatted: "24-Jul-2017". and when i use new Date("24-Jul-2017"); it returns date with one day offset. 2017-07-23T22:00:00.000Z Tried different...
Jon Skeet
people
quotationmark

Assuming the browser is in a time zone with a UTC offset of +2 at the start of July 24th 2017, it's behaving as documented. The Date constructor is documented as behaving like Date.parse, which then includes this documentation - along... more 10/26/2017 9:04:54 PM

people

Why does a lambda expression in C# cause a memory leak?

Note: this is not just some random useless code, this is an attempt to reproduce an issue with lambda expressions and memory leaks in C#. Examine the following program in C#....
Jon Skeet
people
quotationmark

I suspect that what you're seeing is the effect of a compiler optimization. Suppose Test() is called multiple times. The compiler could create a new delegate each time - but that seems a little wasteful. The lambda expression doesn't... more 10/26/2017 8:22:15 PM

people

Why value type fields may be instantiated, instead of initialized?

A value type local variable (e.g. S s; given struct S{}) is initialized though the invocation of its constructor (e.g. a = new S(11)), if S declares a constructor with int...
Jon Skeet
people
quotationmark

Basically, this behaviour is required in order to separate the constructor call from the assignment. The expected observable behaviour is that if a constructor throws an exception, the assignment doesn't take place. That won't be the case... more 10/25/2017 4:09:32 PM

people