Browsing 7239 questions and answers with Jon Skeet
I'd just use DefaultIfEmpty: int maxLength = l.Select(s => s.Length).DefaultIfEmpty().Max(); Or to specify a default: int maxLength = l.Select(s => s.Length).DefaultIfEmpty(-1).Max(); Or use a nullable value so you can tell the... more 1/29/2014 10:45:30 PM
You're never initializing lns in Protocol, so it's always a null reference. You may be able to get away with just changing the declaration to: private List<String> lns = new ArrayList<String>(); (I've made it private and... more 1/29/2014 10:23:27 PM
I believe you want a combination of stripTrailingZeros, precision and scale, as demonstrated here: import java.math.*; public class Test { public static void main(String[] args) { test("5000"); // 4 ... more 1/29/2014 10:19:41 PM
You use the AssemblyKeyFileAttribute - it's basically equivalent to the command-line flag (as far as I'm aware) but less flexible due to being part of the source code, and it leaks the keyfile path information into the assembly itself.... more 1/29/2014 9:45:15 PM
Do both of them initialize x to be have the long data type? Absolutely. The type of the variable is entirely determined by the declaration part, not the initialization. Your first form is logically equivalent to: long x = (long)... more 1/29/2014 8:50:26 PM
Assuming you mean this Calendar control, you should just use the SelectedDate or SelectedDates property - let the control handle the conversions. In general, you should avoid performing textual conversions unless you really need to. (This... more 1/29/2014 8:43:25 PM
If you want to wait for a piece of code to finish executing, instead of using Parallel.Invoke, why not just call the code directly? Well normally you'd call Parallel.Invoke with multiple pieces of work. If you execute those pieces of... more 1/29/2014 8:33:13 PM
I think this is what you're after: public class Test { public static void main(String[] args) { System.out.println(trimStart("&%Hell$o")); // [ and ] are between A-Z and a-z... ... more 1/29/2014 7:54:43 PM
To look at what the C# compiler does for you, you need to look at the IL. If you want to see how that affects the JITted code, you'll need to look at the native code as described by Scott Chamberlain. Be aware that the JITted code will... more 1/29/2014 7:44:58 PM
ByteArrayOutputStream is just overriding the abstract method declared in OutputStream. So the real question is why OutputStream.write(int) is declared that way, when its stated goal is to write a single byte to the stream. The... more 1/29/2014 6:56:17 PM