Browsing 7239 questions and answers with Jon Skeet

TextBlock not aligning text correctly C#

So I have a textblock that is receiving response text from a webclient When I do this call in a browser I get nicely formatted responses like this but when I do this in code...
Jon Skeet
people
quotationmark

No, xml:space = preserve is talking about whitespace within the XAML. It's not useful to you here. The important point is that the browser is displaying it with a monospaced font, whereas you're using a variable-width... more 12/26/2013 8:13:54 PM

people

How to use LINQ to XML for receiving data in List format

use c#, .net 4.5 Yesterday i'm asking about how to read xml file. As yesterday was explained i can use Descendants() and Elements() for getting required elements of my...
Jon Skeet
people
quotationmark

You're calling ToString on a query - that's not on a single element. Even if you fixed that, you'd add lots of references to the same object to your list... and this can all be done much more clearly with LINQ: List<Book> books =... more 12/26/2013 8:11:26 PM

people

Socket Programming Simple Client/Server Application

I've have this code here of a simple Client/Server application. How it works: The client enters "get time", and the server responds with the time. The problem is that a...
Jon Skeet
people
quotationmark

EDIT: Ah, I was mistaken in what was wrong. This is the problem. serverSocket.BeginAccept(new AsyncCallback(RecieveCallback), null); Note that you're using RecieveCallback instead of AcceptCallback. So you end up in RecieveCallback... more 12/26/2013 7:54:41 PM

people

Erro parsing XML: not well formed (invalid token)

I checked maximum solutions given in website but still i'm not able to find error and solve this problem. Please help me to solve this problem. here is my code <?xml...
Jon Skeet
people
quotationmark

I suspect this is the problem: android:xmlns:facebook="http://schemas.android.com/apk/res-auto" I'd expect it to just be: xmlns:facebook="http://schemas.android.com/apk/res-auto" more 12/26/2013 9:33:18 AM

people

How to write a "UTF 16" encoding File over FTP in java

I want to write a file directly in the FTP server using java and which needs to be in the UTF-16 format so that I can have support of latin,chinese,etc. characters . Any...
Jon Skeet
people
quotationmark

Well, to start with it doesn't need to be UTF-16 to support all characters - I'd recommend UTF-8 instead of UTF-16. However, basically you should transfer it as if it's a just a binary file (in binary mode in FTP). That way the bytes will... more 12/26/2013 9:20:29 AM

people

how the System.out.println works?

System is a class and out is a static reference variable in the system class that will gives the reference for the printstrem class to access println method. How the printstrem...
Jon Skeet
people
quotationmark

System.out is a bit special. Even though it's a final field, it's manipulated by native code - which is how System.setOut is able to work. When the System class is initialized, System.out is initialized in native code to a reference to an... more 12/26/2013 9:08:07 AM

people

Shared data and unique data among multiple threads

In Java which code is shared between multiple threads and which code is being copied to be used for one particular thread ? Too be more precise if one would consider the...
Jon Skeet
people
quotationmark

No, a is a local variable. That means each invocation of foo gets its own separate variable - whether that's in multiple threads or even recursively within the same thread. Note that this isn't about sharing code - it's about sharing... more 12/25/2013 8:53:03 PM

people

Linq to XML parse a node into dictionary

I can't figure this one out myself. My XML file looks like this: <section name="blah"> <setting1 name="blah">blah</setting1> <setting1...
Jon Skeet
people
quotationmark

While you could hard-code the names as variables, I suspect you'd be better off with a Dictionary<string, Dictionary<string, string>>: var settings = element.Elements("section") .ToDictionary(section =>... more 12/25/2013 1:18:53 PM

people

Extension method to compare two objects for unit testing

I want to write an extension methods for compare some proprties of two objects. I wrote this code: public static void AreTwoObjectsEqual(this Assert asr, object Actual, object...
Jon Skeet
people
quotationmark

Well the compiler error message is fairly clear: Assert is a static class, so you can't use that as the parameter type for the extension method. It's not clear why you wanted to in the first place, to be honest. If you were hoping to be... more 12/25/2013 8:22:43 AM

people

Querying an Xml Document for elements using Linq

I am using XDocument to work with XML data. My Xml has the following structure <Info> <ProductDetails> <ProductDetail> ...
Jon Skeet
people
quotationmark

It sounds like you want to find the first ProductDetail element with a given product ID. This would do the trick for that: public XElement FindProduct(XDocument doc, int id) { return doc.Descendants("ProductId") ... more 12/24/2013 7:34:17 PM

people