Browsing 7239 questions and answers with Jon Skeet

IllegalArgumentException when passing an Array as parameter during method invocation

I must miss something very fundamental. When I try to pass an array of any kind during a method invocation I get an error. However when I do it normally it works. This is the...
Jon Skeet
people
quotationmark

The problem is that the second parameter to invoke is meant to be an array of arguments - you're only specifying a single argument. In most cases that would be okay as the second parameter of Method.invoke is a varargs parameter, but as... more 9/3/2015 9:03:10 PM

people

writing string to outputstream in java

I have a simple servlet class returns CSV file to a client (browser). When I tried to write string to stream. Initially I have followed example A) however I noticed that subset of...
Jon Skeet
people
quotationmark

Look at this loop: while (in.read(bytes,0,4096) != -1) { out.write(bytes,0,4096); } However much data is read by read, you're always writing out 4096 bytes. You only want to copy the same amount of data you've read, e.g. int... more 9/3/2015 8:25:07 PM

people

Why am I required to reference System.Numerics with this simple LINQ expression?

To start, I know how to reference System.Numerics to give the compiler access to the Complex type it's asking for, I just don't understand why it's necessary. I have this basic...
Jon Skeet
people
quotationmark

I believe the problem is due to Accord.Math.ComplexMatrix - a static class with a bunch of extension methods, including: public static double[,] ToArray(this Complex[] c); I get the error with: using static... more 9/3/2015 4:45:07 PM

people

Why Implement the IEquatable<T> Interface

I have been reading articles and understand interfaces to an extent however, if i wanted to right my own custom Equals method, it seems I can do this without implementing the...
Jon Skeet
people
quotationmark

Now if i dont implement the interface and leave : IEquatable out of the code, it seems the application operates exactly the same. Well, that depends on what "the application" does. For example: List<Address> addresses = new... more 9/3/2015 2:49:23 PM

people

Inserting one XML file into another via for loop (XDocument)

This is something I haven't done before, so I might be doing it wrong to begin with, if I am, please let me know. I created a root XML file with XDocument with: public void...
Jon Skeet
people
quotationmark

It sounds like you just need: receipt.Root.Add(enternode); In other words, adding the new element to the root element of the document. There are likely to be rather simpler ways of doing all of this using LINQ, btw. I suspect you want... more 9/3/2015 11:49:37 AM

people

Issue with HOUR_OF_DAY of Calendar

In Debug mode I see that the value I'm parsing is equal to "2015-09-01 22:00". When I create a Calendar I see that HOUR_OF_DAY is equal to 22. However, interval is equal to 10...
Jon Skeet
people
quotationmark

You're not asking for the HOUR_OF_DAY value - you're asking for the HOUR_OF_DAY - 1 value, which actually corresponds to Calendar.HOUR - the 12-hour version: Field number for get and set indicating the hour of the morning or afternoon.... more 9/3/2015 11:08:41 AM

people

Unit Testing Json Result

In my controller I have the following Json method: [HttpPost] public JsonResult GetStatuses() { var allItems = rep.GetStatuses() .OrderBy(i => i.Name) ...
Jon Skeet
people
quotationmark

Just parse the JSON, e.g. using Json.NET: JsonResult result = testController.GetStatuses(); string json = (string) result.Data; List<Status> statuses = JsonConvert.DeserializeObject<List<Status>>(json); // Check... more 9/3/2015 11:05:47 AM

people

How to identify zero width character?

Visual Studio 2015 found an unexpected character in my code (error CS1056) How can I identify what the character is? It's a zero-width character so I can't see it. I'd like to...
Jon Skeet
people
quotationmark

I have a little bit of Javascript embedded within my explanation of Unicode which allows you to see the Unicode characters you copy/paste into a textbox. (I've created a tinyurl for it of http://tinyurl.com/unicode-explorer). Your example... more 9/3/2015 9:15:38 AM

people

C# Xml to Linq remove an item

I'm trying to remove an item with xml to linq but I can't get it to work: Xml <books> <book> <title>Harry Potter und der Stein der...
Jon Skeet
people
quotationmark

I would suggest using Element instead of Elements, and casting the XElement to string instead of using Value. Combine that with using Title instead of title and it should be fine: xmlDoc.Descendants("books") .Elements("book") ... more 9/3/2015 8:59:38 AM

people

XmlSerializer exception when deserializing derived class (<Derived xmlns=''> was not expected)

I am trying to serialize and deserialize a hierarchy of classes using XmlSerializer. The serialization works fine, but when I try to deserialize I get this exception: ...
Jon Skeet
people
quotationmark

You're creating an XmlSerializer which expects to deserialize just Base objects. It doesn't expect to see a <Derived> element. If you use XmlSerializer deserializer = new XmlSerializer(typeof(Derived)); you don't get the... more 9/3/2015 6:22:47 AM

people