Browsing 7239 questions and answers with Jon Skeet
No, I don't think you need to be using OfType<> at all. I suspect you really want GroupBy: var countsByType = animals.GroupBy(x => x.GetType(), (t, g) => new { Type = t, Count = g.Count()... more 2/10/2015 9:42:16 AM
Your client has been set up to only send 5 characters at a time, and then flush - so even though the InputStreamReader probably asked for more data than that, it received less, and then found that it could satisfy your request for 5... more 2/9/2015 9:49:59 PM
You're not actually escaping any of the double quotes, as far as the JSON is concerned - the string doesn't contain any backslashes. You can confirm that with Console.WriteLine(jsonString);. The problem is that you've currently got an... more 2/9/2015 9:42:41 PM
Why is the information in the terminal lost when a new InputStreamReader object is created? When you call read() on the InputStreamReader, it's allowed to (and often will) read more data from the stream than you've actually requested,... more 2/9/2015 9:26:19 PM
The >> operator is a "sign-extended" right-shift operator, which means that if the top bit in the original value is set, the bits that are "shifted in" are 1. That keeps the sign of the result the same, basically. You want the... more 2/9/2015 9:07:38 PM
Your method declares that it returns a value of type JSONObject. But this: return payload.toString(); returns a value of type String. There's no implicit conversion from String to JSONObject, hence the compile-time error. If you really... more 2/9/2015 5:52:12 PM
Simply put, it violates the comparison if two indexes have the same cost. It should return 0, but it will return -1. As a trivial violation, that means that compare(index, index) will always return -1, when it must return 0. It's really... more 2/9/2015 5:38:10 PM
Are you looking for Sets.immutableEnumSet (Guava) perhaps? Returns an immutable set instance containing the given enum elements. Internally, the returned set will be backed by an EnumSet. The iteration order of the returned set... more 2/9/2015 3:53:27 PM
In a new C# 6.0 we can define methods and properties using lambda expressions. No, you can't. You can define method and property bodies using syntax which looks like a lambda expression, in that it uses the token =>. However,... more 2/9/2015 1:58:15 PM
In theory (at the IL level) there are basically three members making up the event: add remove raise You can access each of those via a separate EventInfo property (AddMethod, RemoveMethod, RaiseMethod) and check the access modifier for... more 2/9/2015 12:59:46 PM