Browsing 7239 questions and answers with Jon Skeet

How to call a function inside a private class whose name is identical with another function?

Consider following class: class Foo { private class Bar { int operatedNumber; Bar(int x, int y) { operatedNumber = operate(x,y); ...
Jon Skeet
people
quotationmark

Is there a way to call the second operate() function? Yes - you can qualify it with Foo.this to refer to the enclosing instance of Foo: operatedNumber = Foo.this.operate(x,y); more 5/12/2014 9:05:02 PM

people

How to get TimeZoneID from a browser?

Using Javascript, is it possible to get a client's Time Zone ID that maps to the Time zone IDs (or Time zone name) in this list?
Jon Skeet
people
quotationmark

The browser itself is unlikely to know about that list in general, as they're Windows-specific IDs. You may be able to adapt existing time zone detection Javascript code to use the Windows time zones itself, but it's likely to be some... more 5/12/2014 8:59:33 PM

people

Calendar DATE field is not updated

I'm working on some code that takes care of timezone differences (in this case, converting a date from UTC to EST/EDT) and I noticed that I'm getting the incorrect DATE field from...
Jon Skeet
people
quotationmark

You haven't shown us enough code to know what's going on, but your output is very easy to explain: you're calling Date.toString() which always formats the instant in time using the system local time zone. The time zone in the Calendar... more 5/12/2014 4:52:46 PM

people

Namespace, assembly, and inheritance hierarchy when including

Often when including namespaces or assemblies into my code, I often run into strange cases where a namespace is inherited from another, yet classes from the parent namespace are...
Jon Skeet
people
quotationmark

Shouldn't System.Collections already be referenced by any member of System.Collections.Generic, as it is a child? No. There's no inheritance between namespaces. A using directive only imports types from that namespace - it doesn't... more 5/12/2014 4:15:15 PM

people

Use different timezone depending on url with Rails

In my project, I've different " locale " : en, fr, ... We can see it in the URL as localhost:3000/ \locale\ /...... I search gem or methods to make a relation between this...
Jon Skeet
people
quotationmark

Locales generally don't have enough information to specify the time zone. For example: en just means "English" - is that in the US? The UK? Canada? Australia? Somewhere else? Even with a bit more specification, it doesn't pin it down... more 5/12/2014 3:51:38 PM

people

IllegalStateException no last call on a mock available

I'm trying to use EasyMock to test that a method runs a specific number of times but I keep getting an IllegalStateException error and I don't understand why. I'm new to EasyMock...
Jon Skeet
people
quotationmark

The error you're getting is because nothing's calling anything on your mock. Contrary to your naming, mockByte doesn't refer to a mock at all, so using it in an expect call like this is not going to help you. You should be expecting calls... more 5/12/2014 3:44:45 PM

people

When passing in an object that is going to be modified to a method, is there a way to indicate this?

I have an object and it is passed to a method to be altered. This sort of behaviour seems quite rare so I want to make sure that other developers don't trip up on it and it's easy...
Jon Skeet
people
quotationmark

No, returning the same reference doesn't make it clearer - in some cases such a method would be expected to clone the object and return a different version, e.g. string Escape(string input) Indeed, because a void method can't return... more 5/12/2014 2:24:37 PM

people

Java's String.getByte() vs C#

I have some code in Java that use String.getBytes() (without encoding parameters) on some generated string to obtain byte[] which I later use as a key for AES...
Jon Skeet
people
quotationmark

Basically you should specify an encoding in the Java code. Currently, your code will produce different outputs on different systems as it uses the platform-default encoding (e.g. Windows-1252 or UTF-8). I would encourage you to use UTF-8... more 5/12/2014 1:19:03 PM

people

How to get all Names of last child elements of an xml file to a string array

I have an XML like this <Node Name="segment_@85D819AE"> <Node Name="segment_body37sub0"> <Node Name="face_82C1EB14_4"/> </Node> ...
Jon Skeet
people
quotationmark

It sounds like you're just trying to find the names of all elements with no child elements, then project from each of those elements to the Name attribute value: var names = doc.Descendants() // Or Descendants("Node") ... more 5/12/2014 9:30:01 AM

people

how to check there is a row in specific index to avoid IndexOutOfRangeException

I want to to know how to check there is a row in specific index to avoid the following exception : System.IndexOutOfRangeException for example : if (dtNew != null...
Jon Skeet
people
quotationmark

Well if you want to get to row i, you need to change your check from && dtNew.Rows.Count > 0 to && dtNew.Rows.Count > i Currently you're only checking whether there are any rows - i.e. whether dtNew.Rows[0] is... more 5/12/2014 9:25:45 AM

people