Browsing 7239 questions and answers with Jon Skeet

Problems with TimeZoneInfo and DST in .Net

I'm working in a simple application to convert some Unix Timestamp dates to localtime. I'm printing both, UTC time and "E. South America Standard Time" - (GMT-03:00) Brasilia. The...
Jon Skeet
people
quotationmark

Well, you're probably just missing the fact that the Windows time zone data is not the same as the IANA data that Java is using, and that your two Windows 7 boxes probably have a different set of Windows Updates applied. I wouldn't like to... more 6/29/2015 8:19:40 PM

people

How to reference a DLL in scripted ASP.NET

So I have a ASPX page that we have been using like classic ASP because we do not have access to the code behind the file. All of the C# code is nested inside the ASPX page between...
Jon Skeet
people
quotationmark

Those are importing namespaces - that's not the same as adding a reference. (Assemblies and namespaces are different.) You should be able to just add an assembly reference to the project in the normal way, in the "Project References" part... more 6/29/2015 7:55:09 PM

people

Why is selected Object instead of Object[] with primitive array for overloaded methods?

When I run this code: class Test { public static void main(String[] args) throws Exception { someMethod(new int[] {1, 2, 3}); } static void someMethod(Object...
Jon Skeet
people
quotationmark

Because an int[] isn't an Object[] - it's as simple as that. An element of an Object[] has to be a reference - and an element of an int[] is not a reference. JLS section 4.10.3 talks about the subtype relationships for arrays - in... more 6/29/2015 7:15:01 PM

people

Using 2 Calendar class instances to get time difference

I am using the Calendar library within Java to try and figure out a problem with my application: I have two Calendar instances, depart and arrive. depart is leaving at 5:35 pm...
Jon Skeet
people
quotationmark

You're calling getTime() to get a Date instance, and then calling toString() on that, implicitly - that will always use the system local time zone. You want to use SimpleDateFormat so that you can control the time zone used for... more 6/29/2015 3:53:57 PM

people

Convert vb code to c# / bool

Hhe code create inside a class . How do I convert this to c# code ? vb code : Public Shared HBitEnable(16) As Boolean my code in c# public static bool HBitEnable(16) error...
Jon Skeet
people
quotationmark

I believe your VB code is actually declaring an array and initializing it - not declaring a method. (It's not a local variable - it's a public static field.) So the equivalent in C# would be: public static bool[] HBitEnable = new... more 6/29/2015 6:15:47 AM

people

Find run with specific text in it

I have this to find runs with text that starts with #, but I get an empty sequence back: IEnumerable<Run> runs = doc.Descendants<Run>(). Where<Run>(r =>...
Jon Skeet
people
quotationmark

Well your first snippet only gives runs whose first text descendant starts with #. Your second snippet gives all text descendants starting with #. So if you've got any runs with a non-first text descendant starting with #, that will be... more 6/29/2015 6:07:32 AM

people

Alternative for #subList() for String array?

So I modified an API (for command management) to use String[] instead of a list of Strings. My problem is here:strings.subList(1, strings.length) So I need to change this to a...
Jon Skeet
people
quotationmark

You can't get one array which is a sliced view of another - but you can make a list view over an array, and then use sublist on that: List<String> stringList = Arrays.asList(strings); List<String> subList =... more 6/28/2015 11:53:38 AM

people

ToDouble always throws an exception when i want to convert a negative number in string format to Double

when i run the following code it always throws an exception string a = "-12.12"; double b = Convert.ToDouble(a); An exception of type 'System.FormatException' occurred in...
Jon Skeet
people
quotationmark

I strongly suspect you're running in a locale which uses , as the decimal separator... or which uses a different symbol for negation. You can pass in a CultureInfo to specify how to parse - I usually use double.Parse instead of... more 6/27/2015 5:38:33 AM

people

In C#, why doesn't ?: operator work with lambda or method groups?

Does not work: Func<string, byte[]> getFileContents = (Mode != null && Mode.ToUpper() == "TEXT") ? TextFileContents :...
Jon Skeet
people
quotationmark

Anonymous functions and method groups don't have types in themselves - they are merely convertible to delegate types (and expression tree types for some lambda expressions). For the conditional operator to determine the overall type of... more 6/26/2015 7:45:18 PM

people

Java can't find classes in parent package

I'm not sure if this is a classpath problem, a syntax problem, or an access modifier problem. I'm trying to implement packages for the first time in Java and having with the...
Jon Skeet
people
quotationmark

I think you've misunderstood the classpath, for starters. You don't put package directories on the classpath - you only put the root of output directories there. I suggest you compile from the src directory, with the output going to a bin... more 6/26/2015 3:24:41 PM

people