Browsing 7239 questions and answers with Jon Skeet
As noted in a comment, you can do this with overloads and parameters (which can be optional). I blogged about this a while ago, but in your case you'd want: public class ClassConstraint<T> where T : class { } public class... more 2/11/2015 11:33:01 AM
It sounds like you want the template method pattern: public abstract class MyBaseClass { public void Something() { // Code from SomethingAwesome here, or keep SomethingAwesome // separate and call it from here ... more 2/11/2015 9:32:12 AM
Would C# compiler optimize empty void methods away? No. They could still be accessed via reflection, so it's important that the method itself stays. Any call sites are likely to include the call as well - but the JIT may optimize... more 2/11/2015 8:34:49 AM
It sounds like you should just call up to the base class constructor: LineSegmentGeometry(Point endPoint, LineGeometry l) : base(l.StartPoint, l.Direction) { this.endPoint = endPoint; } Note that I'm referring to StartPoint and... more 2/11/2015 8:31:49 AM
You can't just have a statement like: _LangID = int.Parse(Helper.GetAppSetting("LangID_En")); within a class declaration. It would have to be in a method, or constructor, or something like that. However, given that you've just declared... more 2/11/2015 8:19:12 AM
You can't just use generics for this - at least, not easily. You could write something like: public static void IsValidResponse<T>(this Response response, Func<Response, T> firstPropertyFetcher, Func<T, object>... more 2/11/2015 8:02:06 AM
If you're using JUnit 4 (as it looks like you are), you presumably aren't extending an existing test class - so you need to call the static assertArrayEquals with the class name, e.g. import... more 2/10/2015 11:02:34 PM
SelectMany is normally the way to flatten hierarchies, so: var values = myList.SelectMany(foo => foo.Bar) .Select(bar => bar.Value); The SelectMany will give you an IEnumerable<Bar>, and then the Select... more 2/10/2015 2:34:54 PM
The problem is your text format - you've used hh which is the 12-hour clock, but you've got a value of 13. You want HH, which is the 24-hour clock. I'd also recommend quoting the T as you just want the literal T character, and also taking... more 2/10/2015 1:01:38 PM
Is the catch (ClassCastException ccex) block above enough to avoid any issues with that unsafe cast? No, precisely because it's not checked. It will check that it's a Map, but that's all it is at the JVM level, due to type erasure. It... more 2/10/2015 12:56:33 PM