Browsing 7239 questions and answers with Jon Skeet

How do I select items in an XDocument?

In the XML below, I'm trying to retrieve all the trkpt items so that I can perform a task with the lat / lon attribute values. I thought LINQ to XML would be easiest approach but...
Jon Skeet
people
quotationmark

You're using the wrong namespace. The default namespace of the elements (including trkpt) is http://www.topografix.com/GPX/1/1, due to this: xmlns="http://www.topografix.com/GPX/1/1" I would strongly recommend that you change your... more 4/26/2016 5:34:19 PM

people

Why await MethodName is working different from await Task.Run?

you will see a console app codes below. There are two situations I tried. In the first case, I commented await GetProducts() line. In this case, output is: Start Time:...
Jon Skeet
people
quotationmark

This is the problem: await Task.Run(() => { GetProducts(); }); You're not waiting for the task returned by GetProducts() to complete - you're just waiting for the immediate GetProducts() method call to complete. The simplest fix... more 4/26/2016 10:34:12 AM

people

Java Optional evaluation side Effects

I had some trouble with the evaluation of Java optionals. Consider the following test: @Test public void test() { System.out.println("GOT STRING: " +...
Jon Skeet
people
quotationmark

Why is the second option evaluated? Because you're calling the second() method, in order to provide the value as an argument to orElse(). The value of the argument will be ignored (because you already have a value) but that doesn't... more 4/26/2016 10:01:42 AM

people

Deserialise JSON containing numeric key with Json.NET

I would like to deserialize the following JSON (using Json.NET) to an object, but cannot, as the class name would need to begin with a number. An example of this is the Wikipedia...
Jon Skeet
people
quotationmark

It sounds like the Pages property in your Query class would just need to be a Dictionary<int, Page> or Dictionary<string, Page>. Complete example with the JSON you've provided - I've had to guess at some of the name... more 4/25/2016 9:18:41 PM

people

list all property names of controls based on condition in C#

I am trying to parse through all properties of all my controls (for example ascx files) from a certain page (this.Page.Controls) in order to obtain the name of the property that...
Jon Skeet
people
quotationmark

This is the documented behaviour of HtmlContainerControl.InnerHtml - in the "exceptions" section, it's documented that it will throw HttpException if: There is more than one HTML server control. - or - The HTML server control is... more 4/25/2016 6:29:38 PM

people

Can the C# compiler distinguish between I/O bound and computational tasks?

Consider a snippet of code such as this: public async Task<Bitmap> DownloadDataAndRenderImageAsync( CancellationToken cancellationToken) { var imageData = await...
Jon Skeet
people
quotationmark

No. In the example you've given, the compiler will only use TaskCompletionSource<T> (indirectly) for the overall asynchronous operation (DownloadDataAndRenderImageAsync). It's up to the two methods that are called to decide how... more 4/25/2016 4:33:42 PM

people

Linq groupby return unique group

I have list of records, each record has Name and Rounds. Rounds is a concatenated numbers seperated by "-" How can i group by name and display only unique rounds, also count...
Jon Skeet
people
quotationmark

I would start by projecting your entity to a name and collection-of-rounds pair. That will then be easier to work with. For example: var query = results .Select(d => new { d.Name, Results =... more 4/25/2016 12:40:33 PM

people

Progress of dataOutputStream.readFully

I'm receiving a file using dataInputStream.readFully, so i'd like to show the progress of the transmision. Is it possible to know the progress of readFully method? Thank you.
Jon Skeet
people
quotationmark

No - the whole point is that it's a single call to make it simpler to read. If you want to read more gradually (e.g. to update a progress bar) you can just read a chunk at a time with InputStream.read(byte[], int, int) in a loop until... more 4/24/2016 3:06:47 PM

people

how to convert an image into base64 in xamarin.android?

I have this code, it works very well in android studio but not in xamarin bitmap.Compress() has different arguments in xamarin and i am confused how to convert image into base64...
Jon Skeet
people
quotationmark

If you look at the documentation for Bitmap.Compress in Xamarin, you'll see that the last parameter is a Stream. The equivalent of ByteArrayOutputStream in .NET is MemoryStream, so your code would be: Bitmap bitmap =... more 4/24/2016 3:01:00 PM

people

C# ListView repeating 1 column from csv

Importing .csv into a ListView in c# duplicates the first entry. Original csv file: Original file image What I get: Visual Studio Error I am trying to upload the .csv to the...
Jon Skeet
people
quotationmark

I suspect this is the problem: ListViewItem item = new ListViewItem(strArray[0].ToString()); item.SubItems.Add(strArray[0].ToString()); You're adding the first value twice, once as the "main" item and once as a subitem. Try just... more 4/23/2016 8:27:09 AM

people