Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
— Martin Fowler
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
— Martin Fowler
When using Path.Combine, you should be aware of the behavior that if the second parameter has a leading slash, it will ignore the first parameter.
Given the following:
string root = "c:\";string path = "test.txt";string lead = "\test.txt";
We get the following results:
using System.IO;
…Path.Combine(root, path);// ‘c:\test.txt’Path.combine(root, lead);// ‘\test.txt’
Arrange, Act, Assert. Specifically, use separate code paragraphs (groups of lines of code separated by a blank line) for each of the As. Arrange is variable declaration and initialization. Act is invoking the code under test. Assert is using the Assert.* methods to verify that expectations were met. Following this pattern consistently makes it easy to revisit test code.
[source: Principles for Test-Driven Development]
It’s disabled by default and to enable it, add this to the web.config
<configuration>
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
</configuration>
Alternatively, you can enable these protocols in the Machine.config
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="HttpPostLocalhost"/>
<!-- Documentation enables the documentation/test pages -->
<add name="Documentation"/>
</protocols>
[source: INFO: HTTP GET and HTTP POST Are Disabled by Default]
Use the as keyword.
MyClass castedObject = obj as MyClass;
This won’t throw a class cast exception. Instead, castedObject will return null if obj isn’t a MyClass.
You can use multiple ?? operators to chain multiple null comparisons:
string text = value1 ?? value2 ?? String.Empty;
When normalizing strings, it is highly recommended that you use ToUpperInvariant instead of ToLowerInvariant because Microsoft has optimized the code for performing uppercase comparisons.
[source: CLR via C# ]