Browsing 7239 questions and answers with Jon Skeet

Android Studio 1.1 warning with switch case statement

I have a branch which replace system day of week integer value to human readable string value. When I use if-else statement like the following, Android Studio 1.1 does not warn...
Jon Skeet
people
quotationmark

But if I try to use switch-case statement like the following, it warns the value getResources().getString(R.string.sunday) assigned to curStrDayOfWeek is never used. And it's absolutely right - because you'd immediately fall through... more 4/26/2015 12:20:02 PM

people

Thread.join not working

A call to join() Guaranteed to cause the current thread to stop executing until the thread it joins with (in other words, the thread it calls join() on) completes. However, in my...
Jon Skeet
people
quotationmark

However, in my program both the threads are executing simultaneously. Thread1 is not waiting for Thread2 to finish its execution. No, and it wouldn't - because thread 1 isn't calling join. Look at the docs you quoted again: A call... more 4/26/2015 7:36:38 AM

people

Error: Index was outside the bounds of the array

When I'm running this code, I'm getting error Index was outside the bounds of the array. for (var i = 9; i + 2 < lines.Length; i += 3) { Items.Add(new...
Jon Skeet
people
quotationmark

You're using lines[i + 3] in the loop, but your check only ensures that i + 2 is in range - and the fact that you're using 4 values in the loop rather than 4 makes it look like this should probably be: for (var i = 12; i + 3 <... more 4/26/2015 6:45:33 AM

people

C# Remove item from nested dictionary

I've got a simple question that my mind is drawing a blank to: I have a Dictionary that looks something like this: Dictionary<string, Dictionary<string, string>>...
Jon Skeet
people
quotationmark

Well presumably you've got two keys: one for the outer dictionary and one for the nested one. So assuming you know that the entry is present, you can use dict[outerKey].Remove(innerKey); If you don't know whether the entry exists, you... more 4/25/2015 7:49:08 PM

people

Array JSON deserialize

I'm trying to get the data from a website RSS converting it to JSON. I got this JSON string: http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http%3A%2F%2Frss.tecmundo.com.br%2Ffeed I'm using lists to get the values but I got this error "Cannot create an instance of the abstract class or interface" and I don't know how to solve it. It happens in this line. IList<News> content = new IList<News>(); Here is my code. public class News { public string author { get; set; } public string title { get; set; } public string content { get; set; } public string contentSnippet { get; set; } public string link { get; set; } public string publishedDate { get; set; } public string[] getFeed(string Website) { string path = @"http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=" + Website; var json = new WebClient().DownloadString(path); JObject jsonObject = JObject.Parse((string)json); IList<JToken> jsonData = jsonObject["responseData"]["feed"]["entries"]["0"].Children().ToList(); IList<News> content = new IList<News>(); foreach(JToken data in jsonData) { News finalData1 = JsonConvert.DeserializeObject<News>(jsonData.ToString()); content.Add(finalData1); } return new string[] { "I must return something here." }; } } Here is the tool I'm using to visualize better the JSON string: http://jsonschema.net/#/
Jon Skeet
people
quotationmark

The error you're getting has nothing to do with JSON. It is because you're trying to create an instance of an interface. You could just fix that by giving it the concrete List<T> class: IList<News> content = new... more 4/25/2015 6:59:38 PM

people

How to get datetime group by days via LINQ C#

I have a datatable which contains the data of whole month. Now i want to get those data group by days via linq. I already have this query but i need a little change. My day starts...
Jon Skeet
people
quotationmark

Just group by the Day property of the DateTime value, after adjusting the date/time accordingly by 7 hours. Of course, if you actually have multiple months/years involved, that will give you somewhat odd results, but... .GroupBy(row =>... more 4/25/2015 9:49:11 AM

people

Better performance when importing just a part of a library?

Is for example this using SportsStore.Domain.Entities; better than this using SportsStore; ? If that is the case, what does it mean for the performance of my program when...
Jon Skeet
people
quotationmark

They're entirely different. A using directive of that form only tells the compiler to make members of the given namespace available as simple names. It has no effect at execution time - if you didn't have any using directives and just... more 4/25/2015 9:43:20 AM

people

I wanted to understand the purpose of this code snippet

Can someone please explain the purpose of this C# code. It's a code snippet in a Windows based application. Is it counting the number of keypress? What is the purpose of 13...
Jon Skeet
people
quotationmark

That code is unfortunately written - KeyPressEventArgs.KeyChar basically returns the character pressed (so shift-a will return 'A' for example). 13 is just the Unicode character for "carriage return" which is returned when the user hits... more 4/25/2015 9:41:08 AM

people

Cannot resolve method between Enumerable and Queryable candidates

I have this method in a class called Invoice: public static Expression<Func<Invoice, bool>> IsAllocated() { return i => i.TotalAmountDue ==...
Jon Skeet
people
quotationmark

Your method returns an appropriate expression tree already - you just need to call it, not call it in a lambda expression: var filteredInvoices = invoices.Where(Invoice.IsAllocated()); more 4/24/2015 8:00:29 PM

people

java.sql.SQLException: Before start of result set

I don't understand why this isn't working, I keep getting this java.sql.SQLException: Before start of result set error, ive looked online but because ive been staring at a...
Jon Skeet
people
quotationmark

You're calling retrieveMessages() multiple times. It doesn't help that you haven't shown us what that does, but I suspect you want to call it once and store the result in a local variable. At the moment, I suspect you're calling next() on... more 4/24/2015 7:12:36 PM

people