Declaring Different Elements - C# Coding Standard 4

In our application, we use many variables, interfaces, methods, properties, connection on. Today we discuss what are the good practices while working on these elements.

             Don't hardcode the strings that might changed based on deployment environment. For example, development environment can different values for database connection strings, folder paths for files, Active directory server name, Trace and logging file paths...etc when compared with production environment. Always better to place all these string variables  in configuration files like Web.config or App.config. This helps us to modify the values easily while deploying the application in different environments. Even you can create environment variables in each environment server and you no need to worry to change each-time; only difficulty with this approach is you need to change the code to read the values from environment variables instead of reading from configuration file.

             Early binding gives more performance when compared with Late binding. So, use Early binding wherever it is possible instead of late binding.

             Don't write any code inside AssemblyInfo.cs class. Do not place any assembly attributes in any file, place these only in AssemblyInfo.cs file.

             To create strong named assembly, place AssemblyCompany,AssemblyDescription, and AssemblyCopyright details only in AssemblyInfo.cs file.

             Use Settings file to define conditional complication constants instead of defining using #define (explicit preprocessor definition) in code.

             You need to Sign all your assemblies including client application and interop assemblies with .snk file which should have strong password.

Add comment