Browsing 7239 questions and answers with Jon Skeet

Reusing cached instances

I have an application that uses a data structure Point. Let's say that overall there are 50 distinct instances of Point (meaning p1.equals(p2) == false). However during...
Jon Skeet
people
quotationmark

Your map is entirely reasonable. You could create your own wrapper class if you wanted to, but I'd probably stick with the map for the moment. If Set<E> exposed an operation of "get the existing entry which is equal to this one" then... more 1/3/2016 8:29:30 AM

people

What is the significance of the count parameter in Stream.Write/Read?

If I use a buffer that is bigger than the count will the program only take the desired length from the buffer?
Jon Skeet
people
quotationmark

Yes, the count is the maximum number of bytes to be read in a call to Stream.Read, or the exact number of bytes to be written in a call to Stream.Write. Note that Stream.Read returns the actual number of bytes read, which may be less than... more 1/2/2016 1:33:05 PM

people

Asp.NET 5 listen to tcp socket

System.Net.Sockets seems to only be available in Asp.Net 4.5/4.6. Is there a way to do this in Asp.Net 5 or are there plans to?
Jon Skeet
people
quotationmark

You just need a dependency on the System.Net.Sockets nuget package. Here's a complete example: Code: using System; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; public class Program { public static void... more 1/2/2016 9:36:23 AM

people

What's $ operator supposed to mean for a string?

So, I've just had the following conversation with a user in the comments section. Me: Year year = new Year{ State = States.Happy }; Them: eventStream.ReceiveJoke += joke...
Jon Skeet
people
quotationmark

It's an interpolated string literal, introduced in C# 6. It's broadly equivalent to: eventStream.ReceiveJoke += joke => Console.WriteLine(string.Format("Pretty nice joke: {0}, Thanks!!!", joke)); The compiler looks for braces... more 1/1/2016 6:12:04 PM

people

java math.sqrt from array element

I've got two problems. Please find my code attached below: public class Numbers { public static void main(String[] args) { double[] tab = { 9.0, 27, 5, 77 }; ...
Jon Skeet
people
quotationmark

But for the first element i get 0.0 as a square root. why? Because you're not printing out the square root of the element - you're printing out the square root of the index. This: System.out.print(Math.sqrt(y)); should... more 1/1/2016 5:21:41 PM

people

Calculate the size to a Base 64 decoded message

I have a BASE64 encode string: static const unsigned char base64_test_enc[] = "VGVzdCBzdHJpbmcgZm9yIGEgc3RhY2tvdmVyZmxvdy5jb20gcXVlc3Rpb24="; It does not have CRLF-per-72...
Jon Skeet
people
quotationmark

Well, base64 represents 3 bytes in 4 characters... so to start with you just need to divide by 4 and multiply by 3. You then need to account for padding: If the text ends with "==" you need to subtract 2 bytes (as the last group of 4... more 12/31/2015 12:27:09 PM

people

JObject structure How to iterate?

I hope someone can help me out even though this have properly been answered before i just cant seem to find the answer to this particular. My problem is i don't know how to get...
Jon Skeet
people
quotationmark

The first thing to do is understand your structure. It's somewhat odd, because value is actually an array, containing a single object. You should work out what you would want to do if you ever had multiple objects there. Here's an example... more 12/29/2015 8:12:58 AM

people

Why is the Java compiler giving the incoherent ".class expected" compile error?

If I have a piece of code like this: public class ABC { public static void main(String[] args) { if (true) int a = 0; } } When I compile it, Java...
Jon Skeet
people
quotationmark

I suspect the problem is that the only token sequence that can legitimately follow the keyword token of int in this case is . followed by class. The declaration statement you've got at the moment isn't valid because a local variable... more 12/25/2015 1:19:06 PM

people

Why ; not showing any exception?

While I am working with eclipse ID then I suddenly found that I put double semicolon in variable declaration. Below is my statement double defaultValue = 0.0;; I am getting...
Jon Skeet
people
quotationmark

It's an empty statement, that's all. It's perfectly legal, though usually useless. It's specified in section 14.6 of the JLS: An empty statement does nothing.   EmptyStatement:       ; ... more 12/24/2015 11:08:06 AM

people

Difference between assigning a boolean variable a value and assigning a result of a comparison in Java

My collegues passed me some code, and there are problems when I run the code. Here is some part of it boolean purchased = false; conn = DriverManager.getConnection(connectionUrl,...
Jon Skeet
people
quotationmark

What is the difference between those two ways of writing ? as I know both should work the same way. No, definitely not. In your first piece of code, if rs.getInt("purchased") returns a value other than 1, you assign a value of... more 12/23/2015 9:00:55 AM

people