Browsing 7239 questions and answers with Jon Skeet
You should create a static method to retrieve a type by number. With just a few charts like this, it's simplest to do that by just running through all the options. For larger enums, you could create a map for quick lookup. The only thing... more 3/6/2015 5:22:51 PM
In C# 6, you'll be able to write: if (x.Items?.Any() == true) Before that, you could always write your own extensions method: public static bool NotNullOrEmpty<T>(this IEnumerable<T> source) { return source != null... more 3/6/2015 5:13:20 PM
The first error tells me that s doesn't exist outside of the foreach, which makes sense Indeed - it's right. but the second error says otherwise. No, it doesn't. It's telling you that you can't declare the first (nested)... more 3/6/2015 3:07:18 PM
Well here's the problem, in actionPerformed. notify(); You're doing that without a synchronized block, so the thread doesn't own the monitor for this... hence the exception. However, you don't just want a synchronized block, because... more 3/6/2015 2:50:50 PM
Firstly, I'd strongly advise against using getBytes() without a charset parameter. Next, just use the string constructor that takes a byte array and a charset: String s = "anu"; byte[] d = s.getBytes(StandardCharsets.UTF_8); String e =... more 3/6/2015 8:36:37 AM
It sounds like you want to print a substring of your name on each step. So start with the complete name: String name = "Afshan"; and then loop for as many letters as there are (using String.length() to check) and then print the... more 3/6/2015 7:08:37 AM
You might want to add that as an option in this case, but I would recommend against it in general. Having used both the java.util.Calendar API (where you specify the field number you want to fetch or update) and the APIs of Joda Time and... more 3/6/2015 6:49:32 AM
Here's one slightly different way of approach it: // Constraints just to be vaguely reasonable. public static class Reinterpret<T> where T : struct, IComparable<T> { public T Cast(int value) { ... } public T Cast(uint... more 3/5/2015 9:40:11 PM
You can't, basically. Well, you could overload the index, making one take long indexes and one take int indexes for example, but that's very unlikely to be a good idea, and may cause serious irritation to those who come after you... more 3/5/2015 8:39:20 PM
You're only incrementing the variable if you don't return immediately from the loop - if the forecast is Sunny, Rain or Cloudy, you hit a return statement and don't increment i. You can just move i++ to the bit of the loop straight after... more 3/5/2015 8:10:47 PM