![]() Use string interpolation to concatenate short strings, as shown in the following code. Avoid overly complex and convoluted code logic.Write code with clarity and simplicity in mind.They don't have hover or tool tips that display the type of variables. Readers view our samples on the docs platform. Use var only when a reader can infer the type from the expression.Exceptions are for documentation specific to unsigned data types. The use of int is common throughout C#, and it's easier to interact with other libraries when you use int. For example, use string instead of System.String, or int instead of System.Int32. Use the language keywords for data types instead of the runtime types.Be cautious of deadlocks and use Task.ConfigureAwait when appropriate.Use asynchronous programming with async and await for I/O-bound operations.Use LINQ queries and methods for collection manipulation to improve code readability.Use specific exception types to provide meaningful error messages.Only catch exceptions that can be properly handled avoid catching generic exceptions.Avoid obsolete or outdated language constructs.Utilize modern language features and C# versions whenever possible.NET docs team follows to prepare code examples and samples. The following sections describe practices that the. Then, each CI build notifies developers when they violate any of the rules. You configure the rules you want applied to your project. You can use multiple rule sets to enforce corporate-wide standards, team standards, and even granular project standards.Īny configured code analysis tools produce warnings and diagnostics when its rules are violated. editorconfig files in scope to format your code. These tools make it easier for your team to adopt your preferred guidelines. You can start by using the dotnet/docs to use our style as a starting point. You can also create an editorconfig so that Visual Studio automatically enforces your style guidelines. You can enable any of the Code analysis tools to enforce the rules you prefer. Tools can help your team enforce your standards. You're welcome to use our guidelines, or adapt them to your needs. However, if your submission would change these recommendations, open an issue for discussion first. Our guidelines are Open Source and we welcome PRs and issues. We welcome PRs that bring those samples into compliance, or issues that draw our attention to samples we should update. ![]() The guidelines have evolved over time, and you'll find samples that don't follow our guidelines. Our adoption goal mandates that we show code you should write today, even when code written last year doesn't need changes. We update samples more aggressively than most production applications do. Instead, samples show when constructs should be used. Our teaching goal mandates that we don't prohibit any construct. Both the runtime and compiler have strict performance metrics for hot paths. ![]() The teaching and adoption goals are why the docs coding convention differs from the runtime and compiler conventions. They are meant to be an example of common C# conventions, and not an authoritative list (see Framework Design Guidelines for that). They've helped community members participate in the runtime and compiler projects. ![]() We chose those guidelines because they have been tested over several years of Open Source development. NET Runtime, C# Coding Style and C# compiler (roslyn) guidelines. These guidelines are used by Microsoft to develop samples and documentation. That practice raises awareness of new features, and makes them more familiar to all C# developers. Adoption: We aggressively update our samples to use new language features.All samples should conform to the same style. Consistency: Readers expect a consistent experience across our content.Instead, those samples teach when a feature is a good choice. For that reason, we don't place restrictions on any language feature or API. Teaching: The purpose of our samples is to teach all of.We expect that, so we need to make code that's resilient and correct, even after multiple edits. Correctness: Our samples are copied and pasted into your applications.We chose our conventions based on the following goals: ![]() You can take our conventions as-is, or modify them to suit your team's needs. In this series of articles, you learn our coding conventions and the tools we use to enforce them. The dotnet/docs and dotnet/samples projects are no exception. Most projects enforce a consistent style through code conventions. Following industry practices and established guidelines helps ensure that code is easier to understand, maintain, and extend. A code standard is essential for maintaining code readability, consistency, and collaboration within a development team. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |