Browsing 7239 questions and answers with Jon Skeet
There are two separate things to understand here: How you declare a generic method How you call a generic method You need to include the <T> in the method declaration to make it a generic method. Without that, the compiler... more 7/6/2017 6:37:44 AM
If you absolutely have to use an array, then Array.Copy is probably your friend: int[] smallerArray = new int[array.Length - 2000]; Array.Copy(array, 2000, smallerArray, 0, smallerArray.Length); I'd expect that to be a bit more... more 7/5/2017 2:16:36 PM
Operators can't be overridden - they can only be overloaded. So the == operator in object.ReferenceEquals is still comparing references, or you could do the same thing yourself by casting one or both operands: string x = "some... more 7/5/2017 11:28:33 AM
No, there's no such thing as an extension property. But you could create your own class: public sealed class Rank { private static readonly List<Rank> ranks = new List<Rank>(); // Important: these must be initialized... more 7/5/2017 10:12:07 AM
I don't believe it's feasible to get that information from the exception with the current desktop .NET framework. (Although you can do it in the debugger, if you're willing to jump through some hoops.) The good news is that in .NET Core,... more 7/5/2017 6:08:35 AM
If you really need to do this in a string literal, I'd use a verbatim string literal (the @ prefix). In verbatim string literals you need to use "" to represent a double quote. I'd suggest using interpolated string literals too, to make... more 7/5/2017 5:51:57 AM
You're using FileMode.Open, which doesn't truncate the file if it already exists. Just use File.Create instead: using (var stream = File.Create(directory)) { ... } (You could specify FileMode.Create instead, as your post originally... more 7/4/2017 7:39:01 PM
Basically you don't want or need to use BinaryWriter for this. You're calling BinaryWriter.Write(int) which is behaving exactly as documented. Just use FileStream to write a single byte: using (var stream = File.Open(fileName)) { ... more 7/4/2017 11:01:55 AM
I would avoid using the same method. You've got two different requirements: Build a collection of anonymous types for use in the UI Build a list of GUIDs for children of the given node ID (I'm assuming you only want direct children,... more 7/4/2017 8:44:11 AM
If you really, really need to do this with your current structure, you could use reflection. However, you may well find that an enum would be a better fit. Something like: public enum CategoryID { ... more 7/4/2017 8:27:52 AM