Browsing 7239 questions and answers with Jon Skeet

Increment DateTime Variable

I'm trying to create a loop where my date increments by 1 month while it's in the for loop. Currently It's only displaying today's date. And is not incrementing. I want to change...
Jon Skeet
people
quotationmark

DateTime.AddMonths doesn't change the value you call it on - it returns a new value. This is true of all the DateTime methods. There's nothing which changes the value in place, which is a good job as it's a value type and changes would be... more 2/19/2014 5:52:22 PM

people

Unexpected behavior when sorting strings with letters and dashes

If I have some list of strings contain all numbers and dashes they will sort ascending like so: s = s.OrderBy(t =>...
Jon Skeet
people
quotationmark

It's because the default StringComparer is culture-sensitive. As far as I can tell, Comparer<string>.Default delegates to string.CompareTo(string) which uses the current culture: This method performs a word (case-sensitive and... more 2/19/2014 4:38:54 PM

people

Pattern for using two implementations of one class if no common interface available

Imagine we have some interface. We need to use two different implementations of this interface. The implementations exist. But there is a problem: the implementations do not...
Jon Skeet
people
quotationmark

I wouldn't subclass the implementation classes. I'd just use the adapter pattern and delegate to the implementation classes: public final class ActionFirstImplAdapter implements Action { private final ActionFirstImpl delegate; ... more 2/19/2014 3:10:15 PM

people

Null and Space char decoding in ASCII 8 bit encoded file

I have an ASCII-extended txt file and i need to convert it to a byte array. The problem is that the Null char and the space are decoded with the same 0x20 value. How I can...
Jon Skeet
people
quotationmark

I have an ASCII-extended txt file and i need to convert it to a byte array. Then don't go via text at all. If you just want to grab the bytes within a file, that's really easy: byte[] data = File.ReadAllBytes(filePath); Any time... more 2/19/2014 12:53:39 PM

people

Are non disposed resources freed when an object is garbage collected?

I was posed this question, and while I believe I know the answer, I believe I should be 100% certain else I start spreading misinformation! I have this object: public class...
Jon Skeet
people
quotationmark

When this object goes out of scope and is eventually garbage collected, are these two resources then released, or do they remain in memory? Usually some type - often somewhat hidden from the public API - has a handle on a native... more 2/19/2014 12:42:32 PM

people

Linq Get all items between 2 matching elements

Provided a list, I want to select all items between the 2 given. (including the begin and end params) My current solution is as follows: private IEnumerable<string>...
Jon Skeet
people
quotationmark

You can nearly use SkipWhile and TakeWhile, but you want the last item as well - you want the functionality of TakeUntil from MoreLINQ. You can then use: var query = source.SkipWhile(x => x != begin) .TakeUntil(x... more 2/19/2014 10:21:51 AM

people

How to read XML using Linq with Single root and nested child and siblings in it

How to read the elements inside nested childs and siblings in a single root using LINQ My Xml file format <Config xmlns="urn:Configuration"> <Group name="Model"...
Jon Skeet
people
quotationmark

The problem is that you've ignored the namespace which is defaulted in Config. All of the Group elements are in that namespace, but you're looking for descendantse without a namespace. You want: XNamespace ns = "urn:Configuration"; var... more 2/19/2014 10:08:13 AM

people

Is the assembly dll signed when we create key and hit 'build'?

we are trying to sign an assembly dll from VS2010. To sign, we go to the signing tab and create a new key. Then, build the solution. A DLL is generated. Has VS already signed...
Jon Skeet
people
quotationmark

Has VS already signed this DLL? Yes, unless you specifically request delay signing. Note that this means that a configuration which specifies signing requires the key to be present, which doesn't mesh well with the key being a... more 2/19/2014 9:44:32 AM

people

Java: proper design for multierror functionality

I am writing piece of code in Java, which job is to parse configuration file. It's convenient for the end-users, because they can see and fix all parsing errors at once. But it's...
Jon Skeet
people
quotationmark

Why not throw just a single InvalidConfigurationException (I wouldn't use ParsingError - aside from anything else, I wouldn't expect this to be an Error subclass) which contains information about the specific problems? That information... more 2/19/2014 9:24:26 AM

people

Why does nothing write to my file?

I have a program that I am working on and I have an issue with writing a string into my file. The file is created, but the string value that should be written into it ultimately...
Jon Skeet
people
quotationmark

I strongly suspect you're getting exceptions logged - you should improve your exception handling anyway, but if you're going to log exceptions, you really need to look in the logs when things don't work! This is almost certainly the... more 2/18/2014 7:20:14 PM

people