Browsing 7239 questions and answers with Jon Skeet
Sounds like you probably want a simple method like this: public String getValueOrDefault(String value, String defaultValue) { return isNotNullOrEmpty(value) ? value : defaultValue; } Then: String result =... more 7/14/2015 4:31:13 PM
Why is first bit in byte changed with index of last? Basically, bits are usually referred to such that the least-significant bit is bit 0, then the next is bit 1 etc. So for example: Bit: 76543210 Value: 01000110 So a byte with... more 7/14/2015 4:19:36 PM
You only need to check whether the attribute indexer itself returns null: if (node.Attributes["SplitCombinationOperator"] != null) Currently, that's returning null, and you're dereferencing it for the Value property - hence the... more 7/14/2015 3:36:59 PM
Three options: Create a new class or struct composing both: public class AAndB { private readonly A a; private readonly B b; public AAndB(A a, B b) { this.a = a; this.b = b; } // etc } Use... more 7/14/2015 12:32:11 PM
For exceptions you're throwing, you can just pass the message in to the constructor: throw new ArgumentOutOfRangeException("name", "My custom message"); Note that here, name is the name of the parameter that caused the problem. In C# 6,... more 7/14/2015 6:11:36 AM
One option would be to do all of this within the static initializers of the enum. Keep a static field within the enum itself, write a private static method to get the contents of the file, reading it if necessary, and then at the end of... more 7/14/2015 5:51:11 AM
I suspect the problem is that you're using Seconds instead of TotalSeconds. The Seconds property only gives a value in the range [-59, 59] - so 5 minutes and 30 seconds would return 30, not 330, for example. Try: end =... more 7/13/2015 4:19:05 PM
Why it's not allowing me to add properties having alphanumeric keys A property name has to be an identifier. Identifiers in C# can't start with a digit. You can have a digit after the first character, but not as the first... more 7/13/2015 5:53:07 AM
Currently you're trying to specify 5 type arguments here: Testcase. <String, String, Integer, Map<String, Integer>, ImmutableMap<String, Integer>>toImmutableMap2( ... but the method only has 3 type... more 7/12/2015 4:09:26 PM
No, you can't "rename" members like that. You can refer to System.Point as NRowsColumns if you really want, as using NRowsColumns = System.Point; ... but it would still have the same members as System.Point. It would be simpler to just... more 7/12/2015 7:53:25 AM