Home Random Page


CATEGORIES:

BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism






Separation of operators and punctuators

Space character should be placed before and after the following operators and punctuators (if operator or punctuator is placed before line break, the space after it unnecessary):

+ - * / % & | ^ = < >

&& || << >> == != <= >= += -= *=

/= %= &= != ^= <<= >>=

Space before opening round bracket is optional.

Comma should be followed by space (but space is disallowed before comma).

Operators and punctuators can end line, but should not start line.

Line length

It’s recommended not to create source code lines longer than 80 characters.

 

General style recommendations

Structures and classes

Do not declare structures (except for unmanaged code interoperability).

Ref and out parameters

Do not use ref and out parameters (except for unmanaged code interoperability).

Operator overloading

Do not use operator overloading.

Collections

Always try to use System.Collections.Generic classes instead of System.Collections ones as much as possible.

Partial types

Do not put declaration of the single type in several files (do not use partial types until it is forced by IDE).

Anonymous methods

Use anonymous methods cautiously. Generally, apply the following rules:

Ø Use anonymous method if you need up to five code lines;

Ø Use anonymous method if you need to capture one or two external variables.

5.7 C# 3.0 features

Lambda expressions

Ø Prefer methods over lambda expressions when the same code is used repeatedly.

Ø Prefer lambda expressions where anonymous delegates would have been appropriate in C# 2.0.

Extension methods

Ø Try to avoid extension methods usage.

Ø Put extension methods in their own static class.

Ø Consider grouping extension methods that extend a particular class into a single static class, and name that class <ClassName>Extensions.

Ø Keep extension method classes in their own namespace to mitigate potential name collisions (if you run into a name collision you're forced back to using a static method call).

Anonymous types

Do not use anonymous types (except for very short-lived data in LINQ).

Implicitly types local variables

Ø Prefer explicitly-typed local variables.

Ø Do not use var with intrinsic types.

Ø Use var with LINQ statements where the result is not an intrinsic type.

Object initializers

Prefer object initializers to one-property-per-statement object/element initialization.

Automatic properties

Prefer automatic properties over class field when property acts like a simple wrapper.

References



The following materials are referenced within the document:

[1]. .NET Framework General Reference - Naming Guidelines

[2]. C# Language Specification

Glossary

The glossary contains terms and abbreviations that you should be familiar with when reading the document:

Pascal Case

The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. You can use Pascal case for identifiers of three or more characters. For example:

BackColor, TransformationMatrix, DodgeTypeJawCrusher

Camel Case

The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized. For example:

backColor, transformationMatrix, dodgeTypeJawCrusher

Uppercase

All letters in the identifier are capitalized. For example:

IO, UI


Date: 2015-12-24; view: 852


<== previous page | next page ==>
Indentation, spaces and braces | Exercise 4. Work in pairs. Practice the following sentences as in the model.
doclecture.net - lectures - 2014-2024 year. Copyright infringement or personal data (0.007 sec.)