Browsing 7239 questions and answers with Jon Skeet

Load xml data from specific nodes

My xml file is as under <Nodes> <Node> .. .. <Node> <Node> .. .. <Node> <NodeTemplate> .. .. ...
Jon Skeet
people
quotationmark

Sure - ask for just the Node elements: var nodes = xdoc.Root.Elements("Nodes"); foreach (var node in nodes) { ... } Or if you want to do lots of work on the doc without NodeTemplate getting in the... more 3/5/2015 2:29:06 PM

people

C# using Windows File Explorer to set selected file to string array?

I'm starting a new project, and I need to be able to save/load users data. I want them to click a button, then this brings up a file explorer where they select their .txt file....
Jon Skeet
people
quotationmark

Sounds like you're just looking for File.ReadAllLines - once you've got the filename, of courses. You need to separate out the tasks of "let the user select a file" from "read the contents of the file". OpenFileDialog is probably the... more 3/5/2015 12:52:30 PM

people

Reversing GregorianCalender object's add minute method

When adding one minute to a GregorianCalender object, we do like below which adds 1 minute to the time: GregorianCalendar gc = new...
Jon Skeet
people
quotationmark

Sure. The constant value of Calendar.MINUTE is 12 The constant value of Calendar.YEAR is 1 So your second call is equivalent to: gc.add(Calendar.YEAR, 12); And this is why we try not to build APIs like this, of course.... more 3/5/2015 12:10:53 PM

people

Why the async await not working as expected

I am learning TPL (async/await) from a tutorial and I tried to test it out myself using a console application. Please don't be offended by my ignorance. I am sure I am doing wrong...
Jon Skeet
people
quotationmark

No, because in fact you're sleeping for 7 seconds before you print Waiting started. Here's what happens: Main calls ProcessNumber ProcessNumber sleeps for 1 second ProcessNumber calls IncrementNumber IncrementNumber sleeps for 6... more 3/5/2015 11:59:47 AM

people

SimpleDateFormat + java.sql.Timestamp in Jasper Reports

I have a timezone-delicate report in Jasper and I can't really seem to figure out how to show a few dates relative to a timezone. I have a view which returns dates with the...
Jon Skeet
people
quotationmark

SimpleDateFormat takes a Date, not a Calendar - which means it can't be provided the time zone in the value itself. Assuming you need to stick with SimpleDateFormat (rather than using Joda Time or Java 8's java.time, for example) then... more 3/5/2015 10:24:45 AM

people

ArrayList possible to read out the element name?

Heyho everyone! My project is a bit bigger so I decided to short it a bit and showing only the problem code, which i have currently. On the first, im programming on a console....
Jon Skeet
people
quotationmark

No, the value in the ArrayList is just a reference. The fact that you originally referred to it using a different variable is irrelevant. You could use a Map<String, String> instead... but it would be much cleaner to have a Customer... more 3/5/2015 9:48:42 AM

people

C# JSON.NET invalid type

I am curenntly making an thunder storm app for windows phone but i have a problem. When i have converted the JSON string to C# classes i have seen that the class names just...
Jon Skeet
people
quotationmark

It looks like the result property is effectively a map of results - so you can represent that with a Dictionary<,>. This works: using System; using System.Collections.Generic; using System.IO; using System.Linq; using... more 3/5/2015 9:29:25 AM

people

Time zone storage in data type "timestamp with time zone"

In PostgreSQL, the data types timestamp and timestamp with timezone both use 8 bytes. My questions are: What format is used to store date & time in a timestamp? How is the...
Jon Skeet
people
quotationmark

Looking at the documentation: Timestamps are stored either as integers, or (deprecated) floating point numbers I don't believe timestamp with timezone could be correctly encoded within 8 bytes if it actually stored a time zone. Just the... more 3/5/2015 8:10:08 AM

people

Base class field initialization in derived class

1) If I define a field in a base class like myType myField = new MyField(); Will this field be always initialized in a derived class? 2) If I initialize this field through...
Jon Skeet
people
quotationmark

Yes, fields will always be initialized. If you don't explicitly chain to any other constructors, you'll chain to base() implicitly. You'll always end up chaining right up the type hierarchy until you hit Object. My point is to... more 3/5/2015 7:58:07 AM

people

Inner class property make read only to all accessing classes except outer class

I am new to c# and trying to do some coding when I stumbled on this. I don't know how to word it.So first the code.(It is dummy code just to explain my question). public class...
Jon Skeet
people
quotationmark

There's no way of doing that - other than the visibility of the class itself, outer classes have no extra access to the members within a nested class. Two options: Keep a cachingEnabled private field within DatabaseConnector instead,... more 3/5/2015 7:00:39 AM

people