Best Practices for Using Code Snippets - Visual Studio 2015 (original) (raw)


Share via


Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

The code in a code snippet shows only the most basic way to do something. For most applications, the code must be modified to suit the application.

Handling Exceptions

Typically, code snippet Try…Catch blocks catch and rethrow all exceptions. That may not be the right choice for your project. For each exception, there are several ways to respond. For examples, see How to: Handle an Exception Using try/catch (C# Programming Guide) and Try...Catch...Finally Statement.

File Locations

When you adapt file locations to your application, you should think about the following:

Security

How secure a snippet is depends on where it is used in the source code and how it is modified once it is in the code. The following list contains a few of the areas that must be considered.

Downloaded Code Snippets

IntelliSense code snippets installed by Visual Studio are not in themselves a security hazard. However, they can create security risks in your application. Snippets downloaded from the Internet should be treated like any other downloaded content - with extreme caution.

See Also

Visual Basic IntelliSense Code Snippets Securing Applications Code Snippets