Follow variable naming conventions

This page is not yet available in Spanish. We are working on its translation.
If you have any questions or feedback about our current translation project, feel free to reach out to us!

Metadata

ID: csharp-code-style/variable-naming-conventions

Language: C#

Severity: Notice

Category: Code Style

Description

Variable names should follow the camelCase pattern and start with a lowercase letter, except for private and protected fields that should start with _.

Learn More

Non-Compliant Code Examples

class My_Class {
    int MyVariable = 10;

    public void foo() {
        int FooBar = 14;
        DateTimeOffset t1 = TimeZoneInfo.ConvertTime();
    }
}

Compliant Code Examples

public class CertificateHelperTests {
    private const string PemCertPublic = "";
}
class My_Class {
    int _myVariable = 10;
    [TestMethod]
    public void BooleanToIntegerConverterTest()
    {
        var converter = new BooleanToIntegerConverter
        {
            ValueOnTrue = 1,
            ValueOnFalse = 2
        };

        Assert.AreEqual(1, converter.Convert(true, typeof(int), null, null));
        Assert.AreEqual(2, converter.Convert(false, typeof(int), null, null));
    }
}
class My_Class {
    int myVariable = 10;
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: rtrieu/product-analytics-ui-changes