Browsing 7239 questions and answers with Jon Skeet
Is there a way for me to write to the readonly field from the child class? No. A readonly field can only be assigned in the constructor of the type that declares it. Perhaps you should make a protected constructor in the base class... more 3/23/2015 4:14:14 PM
You need to cast to T - but first, somewhat annoyingly, you need to cast to object due to the rules around conversions to type parameters in C#. I would personally get rid of the local variable though, which isn't helping you: private... more 3/23/2015 4:02:28 PM
You're looking for elements called Season directly under the root element... whereas your XML looks like this: <Show> <name>The X-Files</name> <totalseasons>9</totalseasons> <Episodelist> ... more 3/23/2015 1:55:12 PM
My question is, how does it detect that there is something in the inputstream, how does it know when it becomes null? This is more to do with the InputStream from socket.getInputStream() than BufferedReader, really. Any call to... more 3/23/2015 1:08:10 PM
As you're using Java 8, I'd use java.time for this: Convert the integer (ick) into a LocalDate Add however many days you want Convert back to an integer (ick) So something like: static LocalDate dateFromId(int id) { int year = id... more 3/22/2015 4:45:10 PM
The second argument of string.Substring(int, int) is the length of the substring you want - so BuildingAddress = BuildingAddress.Substring(BuildingAddress.IndexOf(' '), ... more 3/22/2015 4:32:02 PM
It sounds like your plugins should be configured via attributes rather than via exposing properties: [Plugin(Name = "My Plugin", SafeName = "MyPlugin" ...)] public class InputMonitor You can access the attributes via reflection without... more 3/22/2015 12:43:47 PM
Because it makes no sense, and leads to misleading code. When reading the code, it gives the impression that a is part of the instance referred to by b. For example, consider: ClassA a1 = new ClassA(); ClassA a2 = new ClassA(); a1.a =... more 3/22/2015 9:40:38 AM
It's just the way the language is defined - when case labels are enum values, that means the switch expression must be an enum of that type, so specifying the enum type everywhere would be redundant. From JLS 14.11: Every case label... more 3/21/2015 10:43:39 AM
You're trying to use the new operator, which requires a type, like this: variable = new SomeType(constructorArguments); You've got new and then a cast. I suspect you just want the cast, without new: // With a using directive for... more 3/21/2015 8:36:47 AM