Browsing 7239 questions and answers with Jon Skeet

Best Method to pause a Thread?

I have a Runnable class which performs an operation continuously in its run method using an infinite while loop. Sometimes a user might want to pause/resume the operation. What is...
Jon Skeet
people
quotationmark

Because it has nothing to do with synchronization, i do not want to use wait/notify. It has everything to do with synchronization. Presumably your user interaction occurs on a different thread - so you're trying to synchronize signals... more 10/8/2013 5:33:00 PM

people

How to parse string into datetime format

I want to parse a date-time string into a DateTime data type. The format of the string is like 08/10/2013 09:49 PM, and I want it to go to the form 2013-10-08...
Jon Skeet
people
quotationmark

Your format string doesn't match your input data. Try a format string of "dd/MM/yyyy HH:mm:ss tt", and see the custom date and time format documentation for more information. Note that rather than catching an exception if it fails, you... more 10/8/2013 4:45:19 PM

people

Converting between time zones with Noda Time

I'm currently trying to ensure that our legacy back-end can support resolving date times based on the user's current time zone (or, more specifically offset). Our servers are in...
Jon Skeet
people
quotationmark

Your first method looks okay, although we don't know what customResolver is. Your second method is a bit off. I'd suggest: public static DateTime ConvertToEasternTimeZoneFromUtc(DateTime utcDateTime) { var easternTimeZone =... more 10/8/2013 4:32:13 PM

people

Checking types in a generic method

I to know if it is possible to have an if statement in a method that will check the type of the generic used. In the case that got me thinking about this I want to handle a pretty...
Jon Skeet
people
quotationmark

I to know if it is possible to have an if statement in a method that will check the type of the generic used. Not in general, no - because of type erasure. Basically the type of T isn't known at execution time. You could use: if... more 10/8/2013 4:02:11 PM

people

deep copy a value type jagged Array without serialization

Since windows phone does not have the System.Runtime.Serialization.Formatters.Binary namespace, i am using the following way: bool[][] newMask =...
Jon Skeet
people
quotationmark

That only makes a shallow copy. To make a deep copy, you'd want something like: bool[][] newMask = new bool[mask.Length][]; for (int i = 0; i < newMask.Length; i++) { newMask[i] = (bool[]) mask[i].Clone(); } From the docs for... more 10/8/2013 3:59:43 PM

people

PrintStream doesn't print correctly unicode characters ( UTF 16)

I want to print correctly unicode (let's say greek characters ) but I have problems. For example : PrintStream oStream = new PrintStream(client.getOutputStream(), true,...
Jon Skeet
people
quotationmark

This is quite possibly the issue: oStream.write(" Customer : Γειά σου\r\n".getBytes()); oStream.write(" ΚΩΔΙΚΟΣ : 00000234242\r\n".getBytes()); You're calling String.getBytes() with no encoding, to get a byte array using the... more 10/8/2013 3:20:06 PM

people

How to preserve the original type of a type variable in Java?

I have the following example: class bounds { private StringBuilder str = new StringBuilder(); public <Type> void add (Type value) { add_specific (value); ...
Jon Skeet
people
quotationmark

This looks to me as if the original type of the argument passed to the add method gets lost in the body of add. Well, type erasure means that Type won't be known at execution time, but that's not the immediate reason you're getting a... more 10/8/2013 3:15:56 PM

people

Getting wrong number of days using JodaTime

I am getting the wrong number of days when finding the difference between two sql dates. The following shows the method: public Vector getAvailRoom(String RoomID) { ...
Jon Skeet
people
quotationmark

This is the problem: formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); Look at your format in terms of the order of day, month and year - then look at your data. I believe you want: formatter = new SimpleDateFormat("yyyy-MM-dd... more 10/8/2013 3:01:54 PM

people

Recursion going back instead of exiting (c#)

I have a problem. The recursion is working fine as long as Item.Length 0. When Item.Length == 0 it skips the line: GetId(Id, result, Items); Goes to the line return Id; with the...
Jon Skeet
people
quotationmark

Well yes, it would. Look at your code: if (Items.Length != 0) GetId(Id, result, Items); Which part of that says that it should exit the method? It doesn't. It just calls GetId and completely ignores the result. Instead, you... more 10/8/2013 8:04:49 AM

people

Why modify an Array of objects don't change my objects?

I have DataRow from grid and I need to modify few columns in one row. So I put all my columns in Array, and tried to modify them but it doesn't work as I wish. I need an...
Jon Skeet
people
quotationmark

You're just changing the value in the array. You happened to initialize that via dataRow["size"] but that doesn't mean there's any perpetual link between the two. If you need changes to be reflected back to the DataRow, I suspect you... more 10/8/2013 7:54:55 AM

people