Browsing 7239 questions and answers with Jon Skeet

The specified argument is outside the range of valid values C#

I keep getting this error: The specified argument is outside the range of valid values. When I run this code in C#: string sourceURL =...
Jon Skeet
people
quotationmark

Does anybody know what could cause this error? I suspect total (or rather, total + 1000) has gone outside the range of the array - you'll get this error if you try to read more than 200K of data. Personally I'd approach it... more 11/28/2013 5:43:28 PM

people

Java buffered Read

I am working on a program for myself that shows all of the different ways to read in a text file. I have used FileWriter and BufferedWriter. My question here is why does the...
Jon Skeet
people
quotationmark

My question here is why does the FileWriter variable need to be wrapped in a BufferedWriter. It doesn't have to be - but you may well get better performance if you do, so that you avoid going to disk as often. Also, you're using... more 11/28/2013 5:35:19 PM

people

Executing parallel tasks > wait for all > make use of result

GetSystems() and GetActions() both returns IEnumerable<T> of different types. What do I need to do to access the results below? Do I need to make use of Task.WaitAll() or...
Jon Skeet
people
quotationmark

You need to use Task<T> in order to use the Result property. Given the comments, it looks like you want: Task<List<SYSTEM>> t1 = ...; Task<List<ACTION>> t2 = ...; Task[] tasks = { t1, t2... more 11/28/2013 2:45:52 PM

people

Why a derived class can't access a protected getter from the base class?

I have a class like this: public class Base { public Base(string name) { this.Name = name; } public string Name { get; set; } public string...
Jon Skeet
people
quotationmark

The getter should be exposed to the base class and all its child classes. No, not quite. This isn't a matter of automatically implemented properties - it's a matter of what protected means. Access to a protected member within a... more 11/28/2013 1:32:12 PM

people

Can extensions methods be called on no object?

Why does the following piece of code work? call: SomeObject sO = null; bool test = sO.TestNull(); code: public static bool TestNull(this SomeObject sO) { return sO ==...
Jon Skeet
people
quotationmark

Is this allowed to work or just a bug? The code after you've edited the question (to call s0.TestNull() instead of null.TestNull() is meant to work, yes. Extension methods are just syntactic sugar for calling static methods as if... more 11/28/2013 12:53:50 PM

people

Size of Strings and Calendar Objects Java

I am doing some basic (edit: reading and writing to a txt file), which requires me to store a bunch of expenses, and their attributes (i.e. name, price, date of purchase, etc.) I...
Jon Skeet
people
quotationmark

I would strongly suggest using Joda Time wherever possible, rather than Calendar and Date - it's a much cleaner date/time API. Beyond that, definitely make your object model match your domain as closely as possible. You're dealing with... more 11/28/2013 11:03:45 AM

people

HttpClient in .net issues 2 requests when providing username and password in NetworkCredentials

When using the HttpClient in .net 4.5 to do basic authentication I'm finding that it's issuing 2 requests. The first fails with a HTTP/1.1 401 Unauthorized and then it resends...
Jon Skeet
people
quotationmark

You could try setting HttpClientHandler.PreAuthenticate as per Tobberoth's answer, although the documentation for that suggests it will only help after the very first request: With the exception of the first request, the... more 11/28/2013 7:22:55 AM

people

Why am I getting extra text nodes as child nodes of root node?

I want to print the child elements of the root node. This is my XML file. <?xml version="1.0"?> <!-- Hi --> <company> <staff id="1001"> ...
Jon Skeet
people
quotationmark

Why the three text nodes are coming over here ? They're the whitespace between the child elements. If you only want the child elements, you should just ignore nodes of other types: for (int i = 0;i < nList.getLength(); i++) { ... more 11/28/2013 7:08:16 AM

people

eclipse java import organizing

in test classes I have the following import import static org.junit.Assert.*; when I do organize import via ctrl + shift + o then it automatically changes to following import...
Jon Skeet
people
quotationmark

Under Window, Preferences, Java, Code Style, Organize Imports there's an option called "Number of static imports needed for .*" - set that to 1. (Another way to find it quickly is just to type "static" into the search box in... more 11/28/2013 7:02:32 AM

people

LINQ Split list into lists by date

I have list of objects List<Payment>. I would like to get list of lists grouped by PaymentDate. Something like that: List<List<Payments>> where each list of the...
Jon Skeet
people
quotationmark

You can either use GroupBy as suggested by others, or you can just create a Lookup: var lookup = payments.ToLookup(payment => payment.PaymentDate.Date); You can iterate over that (using each group's key as the date) or fetch all the... more 11/27/2013 10:17:58 PM

people