Browsing 7239 questions and answers with Jon Skeet

Linq Lambda expression == and Equals operator

var list = new List<string>(); var word = "some word"; list.Add("some word"); list.Add("some sentence"); list.Add(word); I know Equals compare the value stored in the...
Jon Skeet
people
quotationmark

I know Equals compare the value stored in the reference while "==" compares whether two references point to the same object. No, that's just the behaviour of the default == operator for reference types. When both sides of == have a... more 1/5/2017 7:21:52 AM

people

Initialization of an array

I declare an array on dimension n, where n is the max number of elements that the array can contain: int array[] = new int [n]; I have an algorithm that fills this array with...
Jon Skeet
people
quotationmark

You can't, basically - not based on just the array itself. There is no difference between a value which was explicitly set to 0 and one which just defaulted to 0. You could change your array to be of type Integer[] - then you'd have null... more 1/4/2017 5:31:44 PM

people

C# overloaded constructors issue

I have the following class that I use to minimise code duplication when often calling different sets of data from an Oracle database. Primarily I need help to remove the code...
Jon Skeet
people
quotationmark

Normally I'd have a "canonical" constructor which all the other constructors chain to. In your case that would involve creating an empty list though: public UniformData(string sql) : this(sql, new List<SqlParameters>()) { } public... more 1/4/2017 3:12:25 PM

people

C# Nested initialization strangeness

Under the premise that these initialization statements compile List<int> l = new List<int> { 1, 2, 3 }; Dictionary<int, int> d = new Dictionary<int, int>...
Jon Skeet
people
quotationmark

So my question is, why does the expression even compile? It's an object initializer with a collection initializer value. From the C# specification section 7.6.10.2: A member initializer that specifies a collection initializer... more 1/4/2017 2:11:00 PM

people

Java: Why is this a Deadlock when lock is null?

I was having a deadlock scenario in my code. I reproduced the scenario with the following test code (look at the line number comments too). I have one ExecuterService which takes...
Jon Skeet
people
quotationmark

You don't have a deadlock - there's an error just as you expected. The first and second tasks will throw NullPointerException, leaving only the third task running. You can see this if you surround the body of run() in a try/catch... more 1/3/2017 10:59:00 AM

people

C# Skipping parts of code

I got stucked - the first part of the code "// OPEN PRELOADING PAGE" will for some reason not execute and will be skipped. If I comment the rest of the code and only keep this...
Jon Skeet
people
quotationmark

You're calling Response.Redirect at the end of the method. That's going to basically terminate the request with a 302 response. The data you'd previously written to the (buffered) response is irrelevant at that point. Additionally, you... more 1/1/2017 4:17:38 PM

people

Can delegates change parameters in delegate chain? (C#)

We have 1 event, 2 subscribers. When event rises 1st subsriber (function) change parameter and this parameter is of reference type. Will the second subscriber get changed...
Jon Skeet
people
quotationmark

You can't change the parameter to have a different value assuming it's a by-value parameter, but (as always) you may be able to modify the object that the value refers to. Example: using System; using System.Text; class Test { ... more 1/1/2017 12:45:58 PM

people

c# What makes the difference between the two this keywords in the constructor below?

I don't understand the following: In the code found below, Visual Studio tells me, that I can simplify my code by deleting the second this keyword in the constructor. But why...
Jon Skeet
people
quotationmark

The difference is that you've got a parameter called celestialBodyCount - which means that within the constructor, the identifier celestialBodyCount refers to the parameter, so to access the field you have to qualify it with this. You... more 12/31/2016 8:59:04 PM

people

Sentiment analysis through google cloud Library

Now a days i am implementing sentiment analysis through google cloud library,my code is string text = "Feeling Not Well"; var client = LanguageServiceClient.Create(); var...
Jon Skeet
people
quotationmark

You can either use gcloud auth application-default login from the command line (assuming you have the Cloud SDK installed), or generate and download a service account JSON file and then set the GOOGLE_APPLICATION_CREDENTIALS environment... more 12/31/2016 11:16:21 AM

people

Enqueue various method calls with parameters

For a game in which you have to code your own AI, I need to enqueue various method calls with parameters. For example: MessageReceived(string text, Source...
Jon Skeet
people
quotationmark

It outputs 5 five times because by the time you're executing the actions, i is 5. There's only a single i variable, and its lifetime is extended until all anonymous functions that have captured it are eligible for garbage collection. To... more 12/31/2016 10:48:04 AM

people