Browsing 7239 questions and answers with Jon Skeet

Parameter passing in ProcessBuilder returns "Could not find or load main class"

I have the following code which builds my java command and runs process builder. String runCommand[] = {"java", ExerciseSelected + " " + Input}; runpb = new...
Jon Skeet
people
quotationmark

You're effectively trying to run java "Exercise 100" You want two arguments: "Exercise" and "100", so you should have them as different elements in the array: String[] runCommand = { "java", exerciseSelected, input }; Note that if... more 3/22/2018 2:51:34 PM

people

Rounding Time with NodaTime

I have some LocalDateTimes where I need to round the time of day up/down to the nearest minute number according to a list of defined minutes. For instance, if I have the datetime...
Jon Skeet
people
quotationmark

There's a sort of functionality that will help: the idea of "adjusters". If you write your own method that returns a Func<LocalTime, LocalTime> you can apply that to LocalTime, LocalDateTime, OffsetDateTime and OffsetTime (in 2.3+)... more 3/21/2018 7:38:57 AM

people

Is there a way to check if it's DST (Daylight Saving Time) with UTC?

Is there a way to check if it's DST (Daylight Saving Time) with UTC, without using conversion? I don't want to use conversion because it's ambiguous on the 28 october at 2 am....
Jon Skeet
people
quotationmark

Just use TimeZoneInfo.IsDaylightSavingTime, passing in your UTC DateTime value. That will effectively convert that UTC value into the given time zone and check whether the result is in daylight saving time, although whether it actually... more 3/20/2018 2:57:13 PM

people

Call different function based on a boolean

I have a boolean in my function that decide what function to call. Both of the function that are beying called giving back an Array. Now in my eyes Hex[] areaHexes does exists...
Jon Skeet
people
quotationmark

The reason it's not working is that you are currently declaring two local variables called areaHexes, each of which has a scope which is just the block they're declared in - so neither of them is in scope when you try to use... more 3/16/2018 6:58:36 PM

people

How to tell "OfType()" to ignore inherited classes?

In my WPF application, I have the following line: var windowList = Application.Current.Windows.OfType<Window>().ToList(); This is returning 2 results. These results have...
Jon Skeet
people
quotationmark

You can't use OfType on its own to achieve this, but you can use that with a Where clause afterwards: var windowList = Application.Current.Windows .OfType<Window>() .Where(w => w.GetType() == typeof(Window)) ... more 3/16/2018 3:52:49 PM

people

Different result in parsing datetime via calendsr or simpleDateFormatter

I now working with java 1.6 and encounter strange behaviour, may be bug, here is code: import org.junit.Test; import javax.xml.bind.DatatypeConverter; import...
Jon Skeet
people
quotationmark

This is due to the difference between the Julian and Gregorian calendar systems. SimpleDateFormat uses the default calendar system, which I believe to be GregorianCalendar on both your system and mine. GregorianCalendar (despite its name)... more 3/16/2018 11:20:02 AM

people

Can I consolidate this in a generic method?

I have a DataAccessBase class with the following 2 data access methods. One for ExecuteScalar and one for ExecuteNonQuery. Is it possible to consolidate it into one generic method...
Jon Skeet
people
quotationmark

You can definitely avoid the current repetition you've got with a generic method, but I wouldn't try to reduce it to a single method. Here's what I'd potentially do: protected static int ExecuteNonQuery(SqlCommand command) => ... more 3/15/2018 8:40:24 PM

people

Why are there memory allocations when calling a func

I have the following program which construct a local Func from two static methods. But strangely, when I profile the program, it allocated close to a million Func objects. Why...
Jon Skeet
people
quotationmark

You're using a method group conversion to create the Func<long, long, bool> used for the comparerFunc parameter. Unfortunately, the C# 5 specification currently requires that to create a new delegate instance each time it's run. From... more 3/15/2018 12:29:36 PM

people

Open a BufferedReader in UTF 8

I have a csv file with characters like Cité, but after make the insert into the DB, I see this Cit¿ I open the file as a BufferedReader, but I don't know how to do it in...
Jon Skeet
people
quotationmark

You could explictly use a FileInputStream and an InputStreamReader using StandardCharsets.UTF_8, but it's probably simpler to use Files.newBufferedReader: Path path = Paths.get(csvFile); try (BufferedReader reader =... more 3/14/2018 11:56:46 AM

people

Calculate average date difference of multiple rows

I need to calculate the average of the date difference of all of my rows in dataGridView. I implemented NodaTime (which is far more easy than the traditional methods to calculate...
Jon Skeet
people
quotationmark

Unfortunately there's no real concept of an average of Period values, as they're not even directly comparable. For example, is "1 month" longer or shorter than "29 days"? It depends on the month. Moving to an average, what's the of the two... more 3/13/2018 7:05:51 PM

people