Browsing 7239 questions and answers with Jon Skeet

Reading XML in WinRT

I know the web link of an XML file, and I'm using it in my app. It's root element is feed and it has several child elements called entry. Each entry has an element summary which...
Jon Skeet
people
quotationmark

It sounds like you just don't want the cast to string, which is documented as: If the XElement has children, the concatenated string value of all of the element's text and descendant's text is returned. You probably want ToString()... more 3/28/2015 8:44:42 AM

people

Stopwatch System class in java

Could you please tell me, what is the "System. " in this code? and why they used it? when we should use "System. "? Where can I know I should use System. for nanoTime()? // A...
Jon Skeet
people
quotationmark

It's just the java.lang.System class. (The java.lang package is imported automatically.) nanotime() is a static method within System, and out is a static field in System - so it's just making use of those members. If you're not sure what... more 3/28/2015 8:33:46 AM

people

Need to make XML generation code dynamic

Code: //Takes input as values separated by /// string csvString = "row11,row12,row13///row21,row22,row23///row31,row32,row33"; // Read into an array of strings. string[] source...
Jon Skeet
people
quotationmark

I'm having a hard time following the question, but I think you just want to change your select clause to: select new XElement("Client", dbTemplate.Zip(fields, (name, value) => new XElement(name, value))) more 3/28/2015 7:46:13 AM

people

How to get the number of days in a specific month using Java Calendar?

I am creating a simple program that allows the user to see how many days between the months they set. For example From January - March I can get the current day of the month...
Jon Skeet
people
quotationmark

You need to set the calendar to be in that year and month before asking for the maximum value, e.g. with cal.set(year, month, 1); (Or with the calendar constructor as per David's answer.) So: public static int getMaxDaysInMonth(int... more 3/28/2015 7:26:27 AM

people

Strange behaviour of Convert.FromBase64String

Why does the following code var s = "2I=="; var b = Convert.FromBase64String(s); var new_s = Convert.ToBase64String(b); end up with new_s being 2A==? s was originally a...
Jon Skeet
people
quotationmark

"2I==" represents the numbers 54, 8, (padding x2), as per Wikipedia. In other words, the bits represented are: 110110 000100 XXXXXX XXXXXX (Where X represents an "I don't care, it's from padding") However, because the padding... more 3/26/2015 8:19:02 PM

people

Why do reference data types point?

Consider: I understand that for primitive data types, the memory allocated (orange rectangle) contains the thing you want, but for reference data types, the memory allocated...
Jon Skeet
people
quotationmark

How big is that orange rectangle going to be? For primitives, you already know the size already. But what about for objects? For concrete final classes, you'd know how much memory is going to be used already... but what about other... more 3/26/2015 4:59:30 PM

people

C# Assert at compile time Func argument is static

Is there any way at compile time to assert an argument Func is static? This seems like something the compiler could easily check rather than relying on runtime failure. I...
Jon Skeet
people
quotationmark

This seems like something the compiler could easily check rather than relying on runtime failure. Yes, it absolutely could - but only if there's something in the language to prompt it to do so. There isn't, in C# - it's a pretty odd... more 3/26/2015 11:19:47 AM

people

Determining when to download a file based on DateTime

There is a file that needs to be downloaded, the file is ready to download every day at 8pm, as it gets updated by a third party. The file is only downloaded when the user hits a...
Jon Skeet
people
quotationmark

I would take an approach of: Determine the most recent publication time Check whether the current file was downloaded after that I'd do this with my Noda Time, using Instant as the result of the first step and the value I'd remember in... more 3/26/2015 9:28:26 AM

people

How to use constructor with parameters from one without parameters

I have a controller which takes a DbContext and one who does not. I.e.,: public CalendarController() { var db = new DbContext(); CalendarController(db); // <= Not...
Jon Skeet
people
quotationmark

You have to chain to the constructor like this: public CalendarController() : this(new DbContext()) { } That's the syntax for chaining to any constructor in the same class - it doesn't have to be from a parameterless one to a... more 3/25/2015 8:57:10 PM

people

Getting System.InvalidCastException when using OleDbDataReader.GetInt64() after fetching Long from MS Access database

I've been working on a project (with Visual Studio 2013) in which I need to retrieve information from a MS Access 2007 database stored locally. I'm using OleDb to deal with the...
Jon Skeet
people
quotationmark

I forgot to mention, this isn't just me confusing the length of Long Integer in Access is it? I assume that it's 64-bit, please correct me if I'm wrong. Yup, I think that's exactly the problem. For example, from "Field types in MS... more 3/25/2015 7:53:52 PM

people