Browsing 7239 questions and answers with Jon Skeet

Getting the list of days of the current week from DateTime.Now

My paradoxical or perhaps trivial problem is to create me a list of the days in format DD - MM - YY from the date of today . Suppose we have today is the " 11/04/2015 " ok ? I...
Jon Skeet
people
quotationmark

Assuming you always want Monday to Sunday, you just need something like: DateTime today = DateTime.Today; int currentDayOfWeek = (int) today.DayOfWeek; DateTime sunday = today.AddDays(-currentDayOfWeek); DateTime monday =... more 11/4/2015 4:15:08 PM

people

GroupJoin overloaded with IEqualityComparer only compares objects in the inner collection

I have encountered some odd behaviour while implementing a Group Join with a customer IEqualityComparer. The following code demonstrates the behaviour that is the problem for...
Jon Skeet
people
quotationmark

A GroupJoin operation first needs to build a lookup - basically from each projected key in inner to the elements of inner with that key. That's why you're being passed inner values. This happens lazily in terms of "when the first result is... more 11/4/2015 2:08:18 PM

people

Will DataInputStream override bytes with sequential reads

As the title says, could DataInputStream.read() override previously read bytes if there are more bytes available than the size of buffer, if in the first read some bytes were...
Jon Skeet
people
quotationmark

Each time you call read(byte[]), it will: Block until at least one byte is read from the input, or the input is closed Copy bytes from the input into the array, starting at index 0 of the array Return when there are no more bytes... more 11/4/2015 12:46:44 PM

people

'Unable to parse the format string "claimID != '' & userID = %@"'

I am trying to write a NSPredicate to fetch userID and claimID and I am getting the below error. Terminating app due to uncaught exception NSInvalidArgumentException', reason:...
Jon Skeet
people
quotationmark

Looking at the predicate string format, it looks like & isn't a valid operator. You either want AND or &&. So: @"claimID != '' && userID = %@" or @"claimID != '' AND userID = %@" (This may well not be the only... more 11/4/2015 12:24:48 PM

people

I can't get <pmlcore:Sensor with XElement

I'm developing an ASP.NET MVC application with .NET Framework 4.5.1 that returns XML generated from database data. I want to obtain this: <?xml version="1.0"...
Jon Skeet
people
quotationmark

The problem is that you're adding the wrong namespace... you're trying to use the alias for it, instead of the namespace URI. Here's a concrete example that works: using System; using System.Xml.Linq; class Program { static void... more 11/4/2015 11:26:17 AM

people

Using Synchronized Keyword in threads, but result is not correct?

I'm trying to make use of the keyword "synchronized" but the results are not correct. I'm not able to figure out why call to third object is given before the second one. Expected...
Jon Skeet
people
quotationmark

You're starting three threads. Each of those will call call on the same Callme, so only one thread will be executing call at a time... but that doesn't mean that the threads will execute in the order that you started them. Imagine you... more 11/4/2015 10:46:01 AM

people

SimpleDateFormat throws ParseException in AndroidStudio before compiling

I'm making an app, that is storing some dates in a SQLite db on an android device. Currently, most of it works as intended, except for parsing the text string that i store the...
Jon Skeet
people
quotationmark

It's not that a ParseException is being thrown - the problem is that the compiler is complaining because you're calling parse which can throw a ParseException, and you're not handling it. ParseException is a checked exception, which means... more 11/4/2015 10:39:28 AM

people

Java adding a number to array element

So I got 2 methods. One which will create a multi level array and pass that and a number to my other method. My other method will then add the number to each element in the array...
Jon Skeet
people
quotationmark

My other method will then add the number to each element in the array That's not what it's doing at the moment. It's modifying each "diagonal" element. Imagine that you have a 5 x 10 array... you're currently only modifying 5 entries.... more 11/4/2015 9:46:53 AM

people

Serially assign values to OrderedDictionary c#

I have 2 key value pairs, now i want to fill up the larger one with values from the smaller one in a serial manner. OrderedDictionary pickersPool = new OrderedDictionary(); //...
Jon Skeet
people
quotationmark

It sounds like you should start with a List<string> (or possibly a List<int>, given that they all seem to be integers...) rather than populating your map with empty entries to start with. So something like: List<string>... more 11/4/2015 9:36:00 AM

people

Should I use a field or a property?

First of all, I have read the question asking for the difference between fields and properties and I know what it is used for. Now on to my question, I wanted to create a...
Jon Skeet
people
quotationmark

should I use a field or a property when a property would simply use get;set;? Use a property... for the practical reasons below, and for the philosophical reasons that properties expose a state API, whereas fields expose a state... more 11/4/2015 8:09:57 AM

people