Browsing 7239 questions and answers with Jon Skeet

Add new XElements with new line in XDocument with PreserveWhitespace LoadOptions

I'm trying to edit XML file saving its format: <root> <files> <file>a</file> <file>b</file> ...
Jon Skeet
people
quotationmark

The problem appears to be caused by your use of LoadOptions.PreserveWhitespace. This seems to trump XmlWriterSettings.Indent - you've basically said, "I care about this whitespace"... "Oh, now I don't." If you remove that option, just... more 12/18/2014 2:09:31 PM

people

Inserting unsigned integer value into bytebuffer, maintaining binary representation

I'm trying to put the following binary representation into a bytebuffer for 4 bytes. But since Java doesn't do unsigned, I'm having trouble:...
Jon Skeet
people
quotationmark

Just parse it as a long first, and cast the result: int value = (int) Long.parseLong("11111111000000001111111100000000", 2); That handles the fact that int runs out of space, because there's plenty of room in a long. After casting, the... more 12/18/2014 1:59:39 PM

people

Method from superclass cannot be overridden when return type is a List

When I want to return a ArrayList of C2, it's not possible, because the return types are incompatible. package a; class C1 { private final ArrayList<C2> c2s = new...
Jon Skeet
people
quotationmark

You've got two different C2 classes - an ArrayList<a.C2> isn't the same as an ArrayList<b.C2>. They're incompatible to avoid this sort of thing: ArrayList<b.C2> listB = new ArrayList<b.C2>(); ArrayList<a.C2>... more 12/18/2014 11:35:08 AM

people

When is toString() method called

I got an example to override the toString() method. import java.util.Scanner; public class Demo{ String name = ""; String age = ""; Demo(String name, String...
Jon Skeet
people
quotationmark

You're calling System.out.println(test), which is a call to PrintStream.println(Object). That will call toString() on the reference you pass in, via String.valueOf: Prints an Object and then terminate the line. This method calls at... more 12/18/2014 11:20:35 AM

people

Why is an instance of indexing a one dimensional array a BinaryExpression and not a MethodCallExpression?

Indexing an array, regardless of the dimensions, is a method call because it involves invoking the indexer operator. Then why is the overload of the method...
Jon Skeet
people
quotationmark

I suspect it's because that's what it looks like in IL. The CLI has two different kinds of arrays: vectors which are "rank 1, 0 lower bound" arrays, and arrays which are "any rank, any lower bound" arrays. (Yes, the naming is very... more 12/18/2014 11:02:55 AM

people

Read from socket bufferreader forever android

I am trying to make a simple chat server/client application. My server is made in python, using twisted. Everything works good with it, tested it with telnet. Basically the...
Jon Skeet
people
quotationmark

Could it get stuck forever in the while that checks for a new line from socket? Yes, if there's no more data. But I suspect that's not the problem. I suspect the problem is this: Looper.loop(); As far as I can see, you don't need... more 12/18/2014 9:11:32 AM

people

Flexible DateTime parsing on multi culture web application

I have an ASP.NET web application which is multi culture meaning I have en-us, en-ca, fr-ca, etc. My problem is when I am trying to Parse a date 1/22/2014 using DateTime.Parse...
Jon Skeet
people
quotationmark

If you're absolutely sure of the user's culture - and that they'll actually use that - you could use: // I assume that Culture is a valid reference to a CultureInfo... DateTime date = DateTime.Parse(date, Culture); However, I'd strongly... more 12/18/2014 7:16:23 AM

people

C# How is ctrl+A input turned into a smiley?

While learning about Console.ReadLine() in depth, I found something very peculiar. I wrote following code in Main method in a console application in C# string str =...
Jon Skeet
people
quotationmark

The smiley is just how the console displays U+0001 (start of heading) - and that's the character that apparently is read as input from the console when you type Ctrl-A... a bit like the way that if you type Ctrl-G you get U+0007... more 12/18/2014 6:52:54 AM

people

How does object initialisation happening without a constructor?

The purpose of the constructor is to initialize all member variables when an object of this class is created. How does object initialisation without constructor is assigning...
Jon Skeet
people
quotationmark

Your two object creation expressions are equivalent. If you don't specify the (), it's supplied for you by default. So: var foo = new Foo { X = y }; is equivalent to: var foo = new Foo() { X = y }; From the C# 5 specification,... more 12/17/2014 6:42:43 PM

people

Noda Time Countdown

I have written an application to show the remaining time until the next big industry trade-show. (it's about two years in the future at the time of writing) I started off using...
Jon Skeet
people
quotationmark

To determine a "calendrical" amount of time between two events, you want Period as you've already discovered. However, that only deals with local dates and times. To determine a "calendar-neutral" amount of time between two events, you... more 12/17/2014 5:18:00 PM

people