Microsoft c coding conventions




















Rules are always there to follow. Its a different thing, what is the level you are following the rules. Coding conventions are followed for. Below are some examples of our C coding standards, naming conventions, and best practices.

The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. These headers can also be used as visual cues for rapid scanning of source files.

They also provide convenience for rapidly getting to some source location if you set up search strings in your editor and then 'repeat last search' to quickly locate these headers.

Skip to main content. This browser is no longer supported. Download Microsoft Edge More info. Contents Exit focus mode. In the following example, the variable name inputInt is misleading.

It's a string. Avoid the use of var in place of dynamic. Use dynamic when you want run-time type inference. For more information, see Using type dynamic C Programming Guide. Use implicit typing to determine the type of the loop variable in for loops. Don't use implicit typing to determine the type of the loop variable in foreach loops.

Be careful not to accidentally change a type of an element of the iterable collection. For example, it is easy to switch from System. IQueryable to System. IEnumerable in a foreach statement, which changes the execution of a query. In general, use int rather than unsigned types. The use of int is common throughout C , and it is easier to interact with other libraries when you use int.

Use the concise syntax when you initialize arrays on the declaration line. In the following example, note that you can't use var instead of string[]. In a class, define the delegate method. If you create instances of a delegate type, use the concise syntax. In a class, define the delegate type and a method that has a matching signature.

Create an instance of the delegate type and call it. The following declaration shows the condensed syntax. Use a try-catch statement for most exception handling. Simplify your code by using the C using statement. If you have a try-finally statement in which the only code in the finally block is a call to the Dispose method, use a using statement instead. In the following example, the try - finally statement only calls Dispose in the finally block.

In C 8 and later versions, use the new using syntax that doesn't require braces:. If the divisor is 0, the second clause in the if statement would cause a run-time error.

That is, it doesn't evaluate the second expression. Use one of the concise forms of object instantiation, as shown in the following declarations. The second example shows syntax that is available starting in C 9. The following example sets the same properties as the preceding example but doesn't use initializers. If you're defining an event handler that you don't need to remove later, use a lambda expression.



0コメント

  • 1000 / 1000