Browsing 7239 questions and answers with Jon Skeet

The left hand side of an assignment must be a variable, property or indexer

I'm getting an error and I don't know why: static void decoupeTableau(IEnumerable<int> dst, IEnumerable<int> src) { for (int i = 0; i < src.Count() &&...
Jon Skeet
people
quotationmark

Why I'm getting it ? Because you've got an assignment operator where the left hand side is a method call. What did you expect that to do? What code would that call? An assigment has to either set the value of a variable, or call a... more 4/28/2015 3:51:43 PM

people

Getting Compile time error while sorting arrays using generics in java

Here's my code: import java.util.Arrays; import java.util.Collections; import java.util.Comparator; public class SortingUsingGenerics { public static void main(String[]...
Jon Skeet
people
quotationmark

Your instanceof check doesn't really tell the compiler that inputArray is an Integer[] - the compile-time type is still just E[]. However, you can cast perfectly easily, at which point it will work: if (inputArray instanceof Integer[])... more 4/28/2015 3:04:10 PM

people

"Dynamic object does not contain a definition" error in same namespace

This is my first try at dynamic objects. I have a class "Cell" which contains string ID and float value. What I wanted is to take a list of Cells and create one dynamic object...
Jon Skeet
people
quotationmark

The problem is that the compile-time type of your dRow variable is DynamicRow - so the compiler doesn't treat it as a dynamic value. You need to declare the type as dynamic so that execution-time binding is performed: dynamic dRow = new... more 4/28/2015 1:56:03 PM

people

Why JDK8's Base64 uses ISO 8859 1?

I'm writing my own BASE64 encoder/decoder for some constrained environments. And I found that Base64.Encoder#encodeString saying that it uses ISO-8859-1 for construct a String...
Jon Skeet
people
quotationmark

I suspect it's more efficient: converting from ISO-8859-1 back to text is just a matter of promoting each byte straight to a char, whereas for ASCII you'd need to check that the byte is valid ASCII. The result for base64 will always be the... more 4/28/2015 10:16:41 AM

people

Compute times in Java eg. 1900 1710 = 110 mins

is there any way in java to do that? I want it to compute the times like that. 0950-0900 is 50 mins but 1700-1610 = 50 mins instead of 90, 1900-1710 = 110 instead of 190. thanks...
Jon Skeet
people
quotationmark

If you've just got integers, and you don't care about validation, you can do it all without touching time parts at all: public int getMinutesBetween(int time1, int time2) { // Extract hours and minutes from compound values, which are... more 4/28/2015 10:14:20 AM

people

Linq: Date less that x, but next record date is greater that x

I got records in database. Each record has field "Date". For given date=x i need to find records that Date value is less that x, but next record date is greater of...
Jon Skeet
people
quotationmark

The simplest approach IMO is just to find the record that it would find, and check the date afterwards: var result = db.Table .Where(x => x.Date <= target.Date) .OrderByDescending(x => x.Date) ... more 4/28/2015 9:11:15 AM

people

How do I Make label visible before a heavy method is called

I have a method that takes a few seconds to execute. I created also a big label that should appear right before the method is called and disappear when the method is finished to...
Jon Skeet
people
quotationmark

I have a method that takes a few seconds to execute. Then you shouldn't do that in the UI thread, basically. That blocks the UI thread, preventing the UI from updating. You should perform long-running tasks in other threads, but make... more 4/28/2015 8:40:21 AM

people

C# handling multiple events for an Event

I have a static class to handler MS SQL database interaction with an eventhandler like this: public static event EventHandler<SQLExceptionEventArgs>...
Jon Skeet
people
quotationmark

It sounds to me like you should turn your static class into a non-static class. Then you'd have an instance event, and two instances of the class (one per form). At that point, the two event handlers would be appropriately separated.... more 4/28/2015 8:33:07 AM

people

Unambiguous DateTime representation with NodaTime can this be done with less ceremony?

I have a fairly straightforward notion that I want to represent using Noda Time: 04/24/2015 4:00pm America/New_York To create an unambiguous representation, I've done the...
Jon Skeet
people
quotationmark

I'd say that what you've got is actually the best approach at the moment - you're parsing to the right type, in that what you've got in your text ("04/24/2015 4:00pm") really is a local time. (If you've actually got the "America/New_York"... more 4/28/2015 8:06:18 AM

people

Same Calculation, different result?

My goal is to calculate how many percent counter out of cap is. Now I ran over a problem, I can't find the difference between the two formulas below, as far as my mathematical...
Jon Skeet
people
quotationmark

Your mistake is assuming that these are just pure, abstract numbers. I assume that counter is an int... so the second version is evaluated as: int tmp = counter / cap; int i = tmp * 100; Now we're dealing with integer arithmetic here -... more 4/28/2015 7:19:23 AM

people