Skip to content

Examples

Unnecessary using statements

Examples of practices to avoid

    namespace Example
    {
        using System;
        using System.Collections.Generic;

        internal class BadClass
        {
            static void Main(string[] args)
            {
                Console.WriteLine(I'm using statements unnecessarily!);
                Console.WriteLine(I'm bad, shamone!);
            }
        }
    }
Rule ID Rule Title
IDE0005 Using directive is unnecessary.

Use our namespace conventions

Examples of good practice

NhsWales.Wcp.Portal

Examples of practices to avoid

DHCW.Wis.Reports

Consider your use of var

Examples of good practice

    var patient = new Patient();

    Patient myPatient = new Patient();

Examples of practices to avoid

var patientCount = Ward.getPatientCount();

Examples of good practice

int patientCount = Ward.getPatientCount();

Examples of practices to avoid

var myPatient = Demographics.getPerson(NHSNumber);

Examples of good practice

Person myPatient = Demographics.getPerson(NHSNumber);

Name parameters

Examples of good practice

var permissions = getUsersAccessPermissions("ge000001", isLoggedIn: true);

Examples of practices to avoid

var permissions = getUsersAccessPermissions("ge000001", true);

Practical tips

Enable Visual Studio's inline parameter hints to show argument names before function call arguments

Prioritise readability over brevity

Examples of practices to avoid

SearchOnUserName(string id); SearchOnUsersFullName(string nadexID);

Examples of good practice

SearchOnUsersFullName(string activeDirectoryUserId);

Use underscores only in unit test names

Examples of good practice

SearchOnUsersFullName_ValidActiveDirectoryUserIdProvided\_ReturnsUsersFullName()

Examples of practices to avoid

Search_On_UsersFullName(string activeDirectoryUserId);

Ensure boolean names are phrased as questions

Examples of good practice

bool IsTrue;

Examples of practices to avoid

bool conditionChecker;

Examples of good practice

bool IsOpen;

Examples of practices to avoid

bool open;

Examples of good practice

bool IsActive;

Examples of practices to avoid

bool status;

Use prefixes and suffixes only when specified by conventions

Examples of practices to avoid

    string strActiveDirectoryUserId;

    int iPatientCount;

    var iPatientCount;

    GetUsersFullName(string p_activeDirectoryUserId);

Examples of good practice

Prefix Usage Language
I Interface definitions C#
T Generic Type definitions. Simply use T if only one Type is defined. C#
T Type definitions Delphi
P Pointers to Type definitions Delphi
A Use to distinguish parameters with the same name as private member variables. Delphi

Using braces

Examples of practices to avoid

    if (isLoggedIn)
        DisplayHomePage();

    if (isLoggedIn) DisplayHomePage();

Examples of good practice

    if (isLoggedIn)
    {
        DisplayHomePage();
    }

    if (isLoggedIn) { DisplayHomePage(); }
Rule ID Rule Title
IDE0011 Add braces to 'if' statement.

Code comments

{IMAGE PLACEHOLDER}