Category Archives: coding

Use preprocessor directives in C#

Technically C# actually doesn’t have a true preprocessor, but it treats these statements as if they were preprocessor directives. These statements tell C# about how to process pieces of code. The directives are: #if Tests a Boolean value at compile … Continue reading

Posted in coding, syntax | Tagged , , , , , , , , , | Leave a comment

Understand the region and endregion directives in C#

The region and endregion directives define a section of code that you can collapse and expand by clicking the – and + signs to the left of the code window. You can include optional text at the end of the … Continue reading

Posted in coding, syntax | 3 Comments

Use the pragma directive to disable Visual Studio warnings in C#

Visual Studio provides warnings to let you know when your code contains something suspicious. For example, suppose you have XML documentation enabled. (See Use XML comments to provide IntelliSense support and documentation in C# for information about what XML documentation … Continue reading

Posted in coding, syntax | Leave a comment

Remove unnecessary “using” directives in C#

The top of a C# code file often includes series of “using” directives to tell Visual Studio which namespaces are used by the code. When you first create a project, the code files include lots of using directives that might … Continue reading

Posted in coding, performance | Leave a comment

Define custom exception classes in C#

The example Throw standard exceptions in C# explains how to throw exceptions to tell the program about unexpected errors and the example See a hierarchy of useful exception classes for use in C# lists some useful exception classes. But what … Continue reading

Posted in coding | Leave a comment

See a hierarchy of useful exception classes for use in C#

The example Throw standard exceptions in C# explains how to throw exceptions to indicate a problem in a program. Throwing an exception is easiest if you can find an existing exception class that correctly represents your situation. The following list … Continue reading

Posted in coding | 2 Comments

Throw standard exceptions in C#

The example Use try catch blocks to protect against unexpected errors in C# explains how to catch exceptions and briefly mentions that you can use the throw statement to throw your own exceptions. This example shows how to throw standard … Continue reading

Posted in coding | Leave a comment

Tip: Make parentheses matching more visible in C#

Recently someone asked me if there was a Visual Studio add-in that highlighted parentheses, brackets, and braces so it would be easier to tell which closing parenthesis matched which opening parenthesis. (By the way, if you have a question, email … Continue reading

Posted in coding, miscellany | 1 Comment