Category Archives: coding

Understand region directives in C#

Region directives let you define sections of code that you can collapse and expand by clicking the – and + signs to the left in the code window. Each region directive should have a corresponding endregion directive. You can include … Continue reading

Posted in coding, syntax | Tagged , , , , , , , , , , | 3 Comments

Disable Visual Studio warnings in C#

Visual Studio warnings let you know when your code contains something suspicious. For example, suppose you have XML documentation enabled. To enable XML documentation, open the Project menu and select Properties. On the Build tab, check the XML Documentation File … Continue reading

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

Define custom exception classes in C#

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

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

See a hierarchy of exception classes for use in C#

The example Throw a standard exception 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 … Continue reading

Posted in coding | Tagged , , , , , , , , , , , | 2 Comments

Throw standard exceptions in C#

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

Posted in coding | Tagged , , , , , , , , , , , | 2 Comments

Remove unnecessary using directives in C#

The top of a C# code file usually 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 | Tagged , , , , , , , , , | 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. It turns out that Visual Studio already has a … Continue reading

Posted in coding, miscellany, tips | Tagged , , , , , , , , | 1 Comment

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