Browsing 7239 questions and answers with Jon Skeet
Use a class literal instead. It's not clear what AudioLoop is in this case, but unless it's a class in your own library, that's probably not what you want. I suspect you want something like: new Image(display,... more 1/29/2014 5:23:44 PM
It sounds like you probably want something like this: private T CallWithRetries<T>(Func<T> call) { // TODO: Work out number of retries, etc. for (int i = 0; i < 3; i++) { try { return... more 1/29/2014 4:43:45 PM
The point is that you need a way of accessing the single instance which has been created - it's effectively a global variable. That's precisely what a static field achieves. (At least, it's global as far as the relevant classloader is... more 1/29/2014 4:31:17 PM
Judging by the code sample you've given, it looks like the data is encoded using Protocol Buffers, Google's serialization format. Fortunately, there are at least two libraries implementing Protocol Buffers for .NET: protobuf-net:... more 1/29/2014 4:28:58 PM
For the purposes of GetHashCode, you should absolutely call GetHashCode. However, to answer the question as asked (after clarification in comments) here are two options, returning BigInteger (as otherwise you'd only get two characters in... more 1/29/2014 3:06:48 PM
You get an error because it doesn't support the same interface. Imagine a caller like this: AbstractClass x = new ImplementingClass(); x.Do(new SomeClass(), new SomeClass()); That should work - it's just using the AbstractClass abstract... more 1/29/2014 12:21:08 AM
You've definitely implemented it incorrectly. You're returning a Task<int>, but only once all the work has already been done. It seems to me that you should probably just have a synchronous method: private static void... more 1/28/2014 11:42:23 PM
One shouldn't expect anything, really. From the C# specification, section 6.2.1 (emphasis mine): For a conversion from float or double to an integral type [...]. - In an unchecked context, the conversion always succeeds, and proceeds... more 1/28/2014 9:47:18 PM
It sounds like you just need to synchronize the "fetch, check and delete" part. For example: Iterable<String> keys; synchronized (map) { keys = new ArrayList<>(map.keySet()); } for (String key : keys) { synchronized... more 1/28/2014 9:08:28 PM
Well, you could have: private static readonly Dictionary<string, Func<Foo>> SomeSensibleName = new Dictionary<string, Func<Foo>> { { Constant1, () => new Class1() }, { Constant2, () => new... more 1/28/2014 6:53:58 PM