Browsing 7239 questions and answers with Jon Skeet

Method not found on release build

Lately, I encountered a slowdown in my website and already found the cause. The reason behind is because the methods in my DA layer has IEnumerable parameters instead of...
Jon Skeet
people
quotationmark

Why am I encountering this when I built the code in my solution without fail? Because you're rebuilding your BL project as well, presumably. That's fine - the method still exists by name, and the new parameter type is presuambly... more 10/20/2016 3:04:01 PM

people

Java servlet not writing response bytes

I have a few Java servlets (3.x - Tomcat 8) running that generate and return PDF documents. I've never had any problems with any of them. I recently wrote a new servlet to also...
Jon Skeet
people
quotationmark

You're not flushing the BufferedOutputStream - so it's buffering all your data. You should flush that, not the ServletOutputStream. However, if you're only writing a single byte array, there's no point in using BufferedOutputStream anyway... more 10/20/2016 12:21:27 PM

people

Group (previous) elements of array by number of subsequent negative ones

I'm trying to process (in C#) a large data file with some numeric data. Given an array of integers, how can it be split/grouped, so that previous n elements are grouped if next n...
Jon Skeet
people
quotationmark

I'd probably try to stream the whole thing, maintaining a buffer of "current non-negative numbers" and a count of negative numbers. Here's some code which appears to work... I'd expect it to be at least pretty efficient. I'd start with... more 10/20/2016 12:09:30 PM

people

How to convert an Interval to a LocalDate range in NodaTime?

I'm running into a scenario where I need to convert an Interval value to Enumerable collection of LocalDate in NodaTime. How can I do that? Below is the code Interval invl =...
Jon Skeet
people
quotationmark

A slightly alternative approach to the one given by Niyoko: Convert both Instant values into LocalDate Implement a range between them I'm assuming that the interval is exclusive - so if the end point represents exactly midnight in the... more 10/20/2016 9:30:04 AM

people

C# static event handler vs non static event handler

Good day! I want to understand the following issue: Let's say that we have simple EventSubscriber class public class EventSubscriber { public static Delegate...
Jon Skeet
people
quotationmark

The problem is that you're calling Delegate.CreateDelegate with an overload which is expected to work for static methods (or for instance methods where there's an extra delegate parameter which is the target of the method call). All you... more 10/19/2016 9:58:18 PM

people

My if statements will not take new values

The object is to get the average of the entered values. It is to stop when a negative number is entered. I am trying to get the smallest and largest values entered. The problem I...
Jon Skeet
people
quotationmark

Currently you have two loops. One sums the numbers, and the other finds the largest and smallest numbers. Given your output, it sounds like you should be doing it all in one loop - ideally with more useful variable names too. (Your count... more 10/19/2016 4:43:31 PM

people

Nearly identical code with different running time Why?

I'm testing two nearly identical codes with a tiny difference on one of the for loops. The first uses three loops to iterate indexes y,z,x while the second iterated x,z,y. My...
Jon Skeet
people
quotationmark

Basically, you're accessing the memory in a different pattern - your first approach is much more friendly to the memory cache, because you're accessing a lot of data in the same area, then moving on to the next piece of memory, etc. If... more 10/18/2016 11:39:40 AM

people

c# Base64 Encoding Decoding wrong result

I need to create a hash-signature in c#. The pseudo-code example that i need to implement in my c# code: Signatur(Request) = new...
Jon Skeet
people
quotationmark

You're assuming that your key was originally text encoded with UTF-8 - but it looks like it wasn't. You should keep logically binary data as binary data - you don't need your Base64Encode and Base64Decode methods at all. Instead, your... more 10/18/2016 6:20:46 AM

people

int variables being concatenated instead of added inside System.out.println()

Why are total_amount and tax_amount concatenated together as strings instead of added together as numbers in the below println statement? public class Test{ int...
Jon Skeet
people
quotationmark

That's because of operator precedence. Basically, your code is doing the equivalent of: System.out.println(("Total amount : " + total_amount) + tax_amount); So when total_amount is 100, and tax_amount is 20, that ends up... more 10/17/2016 7:48:54 AM

people

How to remove null valued child nodes in Xml using c#

I have an XML Documnet consisting parent nodes and child nodes, <?xml version='1.0' encoding='UTF-8'?> <response> <system_timestamp>2016-10-21...
Jon Skeet
people
quotationmark

e.Value isn't a null reference or an empty string - it's the string "null" because that's the value in your element. You want: doc.Descendants().Where(e => (string) e == "null").Remove(); more 10/17/2016 7:31:12 AM

people