Skip to content

Latest commit

 

History

History
73 lines (58 loc) · 1.17 KB

GCop432.md

File metadata and controls

73 lines (58 loc) · 1.17 KB

GCop 432

"Unnecessary paranthesis should be removed."

Rule description

It is possible in C# to insert parenthesis around virtually any type of expression, statement, or clause, and in many situations use of parenthesis can greatly improve the readability of the code. However, excessive use of parenthesis can have the opposite effect, making it more difficult to read and maintain the code.

Example 1

public int MyMethod()
{
    var localItem = 100;
    ...
    return (localItem * 10);
}

should be 🡻

public int MyMethod()
{
    var localItem = 100;
    ...
    return localItem * 10;
}

Example 2

public void MyMethod(objedct arg, int myVar)
{
    int x = (5 + myVar);
    var localItem = ((MyObjectName)(arg));
}

should be 🡻

public void MyMethod(objedct arg,int myVar)
{
    int x = 5 + myVar;
    var localItem = (MyObjectName)arg;
}

Example 3

public void MyMethod()
{
    if ((IsLocalFileSystemWebService(Url) == true))
    {
        ...
    }
}

should be 🡻

public void MyMethod()
{
    if (IsLocalFileSystemWebService(Url) == true)
    {
        ...
    }
}