Browsing 7239 questions and answers with Jon Skeet

Unable to reference class in main

The first two parameters seem to work but when I add the string I get an error (Line 17 cannot convert string to double). What am I missing here? From everything I've read in my...
Jon Skeet
people
quotationmark

The problem is that your constructor takes two doubles and a string: public SimpleCalc(double num1, double num2, string oper) But you're calling it with three strings: SimpleCalc Calc = new SimpleCalc("{0.0}", "{0.0}", "{0}"); Change... more 2/3/2014 12:01:51 PM

people

Error parsing date string

I need to parse this string as a date: Mon Jun 10 00:00:00 CEST 2013 Here is what I do: SimpleDateFormat sdf = new SimpleDateFormat("ccc MMM dd HH:mm:ss z yyyy"); Date date...
Jon Skeet
people
quotationmark

As others have said, you need EEE instead of ccc - but you should also specify a locale, so that it doesn't try to parse the month and day names (and other things) using your system default locale: SimpleDateFormat sdf = new... more 2/3/2014 10:23:27 AM

people

Joda Time strange hour

I'm trying to initialise a Joda-Time DateTime object with the hour of 12:00 here is how I do this: public static final long MINUTE = 60 * 1000; public static final long...
Jon Skeet
people
quotationmark

You're specifying a number of milliseconds since the Unix epoch, which was midnight UTC. However, you're implicitly using the system default time zone in your DateTime, and I suspect that at the Unix epoch, your system time zone was... more 2/3/2014 10:18:54 AM

people

How to add terminal zeroes after rounding

I'm trying to round to a different number of decimal places each time the user says so. I've been trying BigDecimal dec = new BigDecimal(input).setScale(places,...
Jon Skeet
people
quotationmark

Why would you call doubleValue()? Just avoid doing that. There are two problems with it: A double has no notion of trailing zeroes, unlike BigDecimal Converting between double and BigDecimal (in either direction) is almost always a bad... more 2/3/2014 6:52:44 AM

people

Null returned from ImageIO.read(new ByteArrayInputStream(bs));

I am trying to convert Base64 encoded string (from image) [link to convertor]. Here is how I do this: First I convert the string, which is: String str...
Jon Skeet
people
quotationmark

What did I do wrong? You ignored the fact that the data is Base64-encoded, not UTF-8. To convert the string to bytes to get the original data, you need to reverse that Base64 encoding, for example using this library. byte[]... more 2/2/2014 10:24:25 PM

people

Fields Initilizers (Static or not) and Constructor (Static or not) which one runs first

Something is not clear to me, according to what I read: Field Initializers run before Constructors. Static field Initializers execute before the static constructor is called...
Jon Skeet
people
quotationmark

If a type has no static constructor, field Initializers will execute before the type being used (as I understand : not being instantiated but rather being used) Not necessarily. If there is no static constructor, then static field... more 2/2/2014 6:31:51 PM

people

Assignment gives unexpected answer

Today I've encountered the following problem, to which I can't seem to find a solution: int i, j, k; i = j = k = 3; i = k++; So it seemed logical to me that the variable 'i'...
Jon Skeet
people
quotationmark

Firstly, as noted by JB Nizet, don't do this. Very occasionally I'll use a postfix increment within another expression, for thing likes array[index++] = value; but very often I'll pull it out into two statements for clarity. I wasn't... more 2/2/2014 12:40:41 PM

people

C# SqlCommand initialization string

I'm working on a C# program that someone else wrote. At some point, I encountered SqlConnection connString = new SqlConnection(@"Data Source=***;Initial Catalog=***;Integrated...
Jon Skeet
people
quotationmark

It sounds like it's probably the name of a stored procedure. That's fine, so long as you then have: command.CommandType = CommandType.StoredProcedure; (I hope that the real code has appropriate using statements as well, of course.) more 2/1/2014 8:37:38 PM

people

'Decimal' source code from Microsoft will it build?

I was recently attempting to answer a question that a user posted about why the decimal struct does not declare its Min/Max values as const like every other numeric primitive;...
Jon Skeet
people
quotationmark

There are a few aspects of mscorlib and the like which wouldn't compile as-written, without some interesting hacks. In particular, there are some cyclic dependencies. This is another case, but I think it's reasonable to consider MaxValue... more 2/1/2014 7:42:27 PM

people

Why is UIDatePicker in countdown mode 1 hour behind?

If I set the UIDatePicker's date in countdown mode to "1970-01-01 00:05:00 +0000" it shows [ 1hour | 5min ] - why is that? Set the date (in a different...
Jon Skeet
people
quotationmark

(This is at least somewhat a guess... I'm not an iOS expert at all.) Well it sounds like the problem is precisely because you're using a time zone which is GMT+1 - or was in January 1970, anyway. Basically I think the UIDatePicker is... more 2/1/2014 6:58:34 PM

people