Browsing 7239 questions and answers with Jon Skeet

Central Directory corrupt error in ziparchive

In my c# code I am trying to create a zip folder for the user to download in the browser. So the idea here is that the user clicks on the download button and he gets a zip...
Jon Skeet
people
quotationmark

You're creating the ZipArchive without specifying a mode, which means it's trying to read from it first, but there's nothing to read. You can solve that by specifying ZipArchiveMode.Create in the constructor call. Another problem is that... more 11/13/2015 7:03:26 AM

people

Order of initialization of static members in yield return statements

I just noticed that the initialization of the static members which are returned via yield return is not in the order they are enumerated but in reverse order. Although the C1...
Jon Skeet
people
quotationmark

As per the question comment, static initialization is not always deterministic. However, you can make it deterministic using static constructors: class C1 : B { static C1(){} public static readonly C1 Default = new C1(); } class... more 11/12/2015 4:14:02 PM

people

How to call for a nested xml element directly in c#

this is my xml... <CruiseProduct> <ID>4091</ID> <Name>MS ROYAL RUBY NILE CRUISE</Name> <Description> <p><br>In house music...
Jon Skeet
people
quotationmark

Now that we know you only want the first Image element, it's simple: cruise_Imagerurl = a.Element("Images").Element("Image").Element("URL").Value This assumes there always is at least one image, mind you. If that's not the case, you... more 11/12/2015 11:25:21 AM

people

C# arrays [,] to Java, concept of specific array

I'm re-writing C# code to Java. I'm facing a type of array not supported by Java. int[,] distance; So here are my questions, what is this ? [,] Is it the same thing as [ ][ ]...
Jon Skeet
people
quotationmark

[,] Is it the same thing as [][] ? No. I'll use int as the element type to make things simpler. An int[,] is a rectangular array. It's a single object, which is indexed by two dimensions. Each element of the array Note that you can... more 11/12/2015 9:37:46 AM

people

How to check whether there is within the class of the same class?

I'am sorry for my Engilsh. I have some class like this: public class MainClass { public string message { get; set; } public MainClass forward { get; set; } } And...
Jon Skeet
people
quotationmark

It sounds like you just want recursion: public int GetNestingLevel(MainClass mc) { return mc.forward == null ? 0 : GetNestingLevel(mc.forward) + 1; } Or as part of MainClass itself: public int GetNestingLevel() { return... more 11/12/2015 8:23:48 AM

people

Java8 DateTimeFormatter parse date with both single digit and double digit day

I'm using DateTimeFormatter to parse a date: private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); LocalDate.parse("05/12/2015", parser); // it's...
Jon Skeet
people
quotationmark

Just use d instead of dd - that still allows a leading 0, but doesn't require it. I suspect you'd want to do the same for months as well - it would be odd to have "1-or-2 digit" days but not months... import java.time.*; import... more 11/12/2015 7:52:45 AM

people

Illegal group end indicator error in protobuf decode

I am getting the following error when i try to decode bytearray using protobuf.js decode error: Illegal group end indicator for Message .SampleMessage: 1749 (not a group) at...
Jon Skeet
people
quotationmark

I strongly suspect that this is the problem: ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream()); out.writeObject(msg); Why are you using ObjectOutputStream? That's for Java's native binary serialization... more 11/12/2015 6:54:59 AM

people

In C# can you perform a Range Select within a Range Select?

I ultimately want to get every date for the current year in a List. I have the following which gives me all dates for a given month.. using System; using...
Jon Skeet
people
quotationmark

You're currently selecting a sequence of sequences - which is why when you print each element out, it's showing that it's a WhereSelectEnumeratableIterator. I suspect you actually want to just flatten that, so you should use SelectMany... more 11/11/2015 9:48:05 PM

people

date.getTimezoneOffset() is not returning an expected value

My browser is running in the Eastern Standard Timezone, when call I call date.getTimezoneOffset() I expect -300 to be returned but instead I get 300 var date = new...
Jon Skeet
people
quotationmark

From the Mozilla docs (or devdocs.io): Return value The time-zone offset is the difference, in minutes, between UTC and local time. Note that this means that the offset is positive if the local timezone is behind UTC and negative if... more 11/11/2015 9:18:06 PM

people

Error [D@6521f956 when trying to print an array

I'm trying to print an array which is returned from a method, but I get the error [D@6521f956 in the terminal. As you can see from the code below, I am looping through my array to...
Jon Skeet
people
quotationmark

That's not an error - that's just what you get when you print out a double[] because arrays in Java don't override toString(). Just use Arrays.toString(double[]) instead: double[] result = method.bmiCalculation(heightArray,... more 11/11/2015 9:15:26 PM

people