Browsing 7239 questions and answers with Jon Skeet
TL;DR: The C# compiler is keeping you safe. Effectively, "nested input in an input position makes an output" when it comes to generic variance. Your method has a parameter which itself accepts a TKey, which sort of reverses the... more 8/29/2017 5:33:04 PM
The fact that a method has async as a modifier is an implementation detail of the method. It just means you can write asynchronous code more easily. It doesn't change how the method is called at all. Typically an async method returns Task... more 8/29/2017 3:47:36 PM
tt doesn't exist as one of the format specifiers for custom TimeSpan format strings. That makes sense in that TimeSpan is really meant to be a duration, not a time-of-day value - it's unfortunate that DateTime.TimeOfDay does return a... more 8/29/2017 12:21:28 PM
Look at the arguments you're passing in to newXMLGregorianCalendar: [...].newXMLGregorianCalendar(Calendar.YEAR, Calendar.MONTH+1, Calendar.DAY_OF_MONTH, Calendar.HOUR, Calendar.MINUTE, Calendar.SECOND, ... more 8/28/2017 4:29:40 PM
No, you can't use this in a constructor initializer. You'd have to add call Add(this) afterwards - but you can do that in the Base<TSelf> constructor, so long as you cast to TSelf. You need to cast this to object first before casting... more 8/27/2017 8:15:46 AM
Basically, you've got a problem because your type doesn't override object.Equals(object) in a way consistent with your IEquatable<T> implementation and you're dealing with a collection of the subclasses. SequenceEqual will be using... more 8/25/2017 12:07:24 PM
You use option two - but only use #if in places where you really need it. The example you gave had the same code in both branches. My Noda Time project takes exactly this approach, and we've had very few problems due to that. Where... more 8/22/2017 8:03:00 AM
When you invoke a method with a parameter array, the arguments go at the end, not the beginning (to match the parameter array position). Next, the arguments don't go in parentheses as you've tried to do - that's the syntax for a C# 7 tuple... more 8/19/2017 8:48:36 PM
Well, you definitely want to use OrderByDescending instead of reversing. It's not going to be quite as brief as the SQL, but you could at least use: IQueryable<Entity> GetSortedData(IQueryable<Entity> result, String orderby,... more 8/18/2017 4:44:41 PM
You need to declare your own delegate type for it. For example: using System; public class Thing { public int field1; public string field2; } public delegate ref TOutput FuncRef<TInput, TOutput>(TInput input); public... more 8/18/2017 3:46:13 PM