Browsing 7239 questions and answers with Jon Skeet
HashMap itself doesn't maintain insertion order - but LinkedHashMap does, so use that instead. As documented... HashMap: This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order... more 10/3/2013 4:45:02 PM
For LINQ to Objects (which takes delegates) then you can, yes - using a statement lambda: sourceList.Reverse() .TakeWhile(o => { ... fairly arbitrary code here return someValue; }) ... more 10/3/2013 4:44:01 PM
Just specify the appropriate culture to double.Parse. For example: CultureInfo french = new CultureInfo("fr-FR"); double x = double.Parse("7,50", french); I suspect you actually had "7,5" as a value, however - as "7,50" would be parsed... more 10/3/2013 4:29:04 PM
The premise of the question is flawed, because catching Exception does catch RuntimeException. Demo code: public class Test { public static void main(String[] args) { try { throw new RuntimeException("Bang"); ... more 10/3/2013 4:13:40 PM
My typical loop for this sort of thing looks like this: int bytesRead; while ((bytesRead = input.read(buffer)) != -1) { output.write(buffer, 0, bytesRead); } While I don't usually like performing an assignment within a condition... more 10/3/2013 3:53:10 PM
These two blocks of code should work identically. No they shouldn't - at least in C# 5. In C# 3 and 4 they would, in fact. But in the foreach loop, in C# 5, you have one variable per iteration of the loop. Your lambda expression... more 10/3/2013 2:26:05 PM
Okay, I now believe that this is the problem: ZipInputStream zis = new ZipInputStream(in); out = new FileOutputStream(entryDestination); out.write(zis.read()); out.flush(); out.close(); You're creating a new file, and writing a single... more 10/3/2013 2:19:21 PM
I do it only for readability, since in this case public members have essentially the same visibility as members without any access modifiers (i.e. package visibility). Is that correct? Well that depends. Not if you're overriding... more 10/3/2013 2:12:08 PM
Fortunately, you can't do this. I say "fortunately" because it's very confusing for the reader. I suggest you just write a method instead, e.g. MergeFrom, so that you're code then reads: // Object initializers used for readability. Foo... more 10/3/2013 2:06:49 PM
Not like that, no. You could use delegates: // Ideally make this a readonly field. Action[] actions = { Level1, Level2, Level3, Level4, Level5 }; ... actions[index - 1](); Or you could use reflection, as others have mentioned... but I'd... more 10/3/2013 12:31:47 PM