Browsing 7239 questions and answers with Jon Skeet

How to automatically update the Noda Time database, and how often?

How frequently do I need to update the Noda Time timezone database, and what are the steps to automatically update it?
Jon Skeet
people
quotationmark

How frequently I need to update timezone database. When it changes :) You can find this out by fetching http://nodatime.org/tzdb/latest.txt which always contains the URL of the latest .nzd file. Or if you don't need automation,... more 7/27/2015 2:12:59 PM

people

Inheriting attributes in Java. New instance?

a pretty simple question about inheritance in java: My abstract super class (only relevant content): public abstract class Writer { private final Logger log =...
Jon Skeet
people
quotationmark

Having two separate fields which will always have the same value seems like a really bad idea to me. You don't logically have two different pieces of state, so why have two separate fields? Instead, just use a local variable in write1 to... more 7/27/2015 9:51:37 AM

people

Having problems with date and time editing

Here is my code: private void textBox1_TextChanged(object sender, EventArgs e) { DateTime myDate = DateTime.ParseExact(textBox1.Text, "yyyy-MM-dd H:m:s", ...
Jon Skeet
people
quotationmark

If you want to indicate that the date/time is invalid, use DateTime.TryParseExact to check whether or not it's valid, without throwing an exception. Use the return value (true/false) to determine the validity. Basically, you shouldn't... more 7/27/2015 6:53:09 AM

people

Strange implementation of Object.Equals

I was reading the MSDN documentation about object.Equals. in the remarks part it mentioned: If the two objects do not represent the same object reference and neither is...
Jon Skeet
people
quotationmark

Basically, this would only be of any use to developers with flawed Equals implementations. From the documentation: The following statements must be true for all implementations of the Equals(Object) method. In the list, x, y, and z... more 7/27/2015 6:10:57 AM

people

alternating each Week

I need to implement a mechanism in Java, which alternates a statement each week, eg. in week one it sets a variable to 10, in week two it sets it to 15 and in week 3 it sets it to...
Jon Skeet
people
quotationmark

You'd need to know the number of weeks in each year, so you could work out whether your condition was enabled for odd weeks or even weeks. You can't just work out whether this year or last year has an even or odd number of weeks in the... more 7/27/2015 5:51:22 AM

people

Java file transfer client not reading all bytes

I have a file sender and receiver. From the 10 or so posts I've found on the internet, this is the correct way to send files through sockets in Java. Take a look at the code...
Jon Skeet
people
quotationmark

You shouldn't try to read more data than expected. Your loop should be: int n; int bytesLeft = fileSize; byte[] buffer = new byte[8192]; while (bytesLeft > 0) { int n = bis.read(buffer, 0, Math.min(buffer.length, bytesLeft)); ... more 7/26/2015 10:08:08 PM

people

Convert a generic collection to a XML in C#

I want to write a generic method that returns a XML once a collection of type T is passed. I tried below code, but doesn't work as expected. Any advise on enhancing this to...
Jon Skeet
people
quotationmark

I don't think you've understood what the argument to PropertyInfo.GetValue is meant to be - it's meant to be the target of the property fetch, whereas you're passing in the PropertyInfo itself. Additionally, your method only has one... more 7/26/2015 11:23:47 AM

people

A Day at the Races Head first C#

I'm working on C# Lab in Head First C# book. When I push start button - dogs should run until one of them reach the finish. Each dog should run with random speed, but all of my...
Jon Skeet
people
quotationmark

Your Run method creates a new instance of Random(). I suspect you don't want to do that - after all, you've already got a property called MyRandom which you're populating when you create the array. Just take out the line: MyRandom = new... more 7/26/2015 8:44:46 AM

people

Find and change the value of first element in list that meets a requirement, do something else if not found

This seems to be ridiculously easy, but I just can't seem to find a way to do it. Basically the title, I want to find the first item in my list that meets a requirement, and...
Jon Skeet
people
quotationmark

FirstOrDefault will return a null reference if no element is found - assuming the element type is a reference type. Instead of calling Equals on the result, just use ==... and don't call it twice: var first = bar.FirstOrDefault(c =>... more 7/26/2015 7:23:28 AM

people

Why does C# is keyword return true for double, but false for float even though casting to float works?

Motivation: I have a method that returns a dynamic datatype. The value is coming from a database and I know that the value will either be a float, double, or string. I don't...
Jon Skeet
people
quotationmark

Right, this is because the type is dynamic. That basically means the meaning of the float cast depends on the execution-time type of the value. The is operator is checking whether float and double are the same type - and they're not,... more 7/25/2015 9:20:02 PM

people