Skip to content

Latest commit

 

History

History
48 lines (35 loc) · 594 Bytes

File metadata and controls

48 lines (35 loc) · 594 Bytes

GCop 418

"Remove the unnecessary casting."

Rule description

You should not use explicit casting code such as (TypeX)someValue where someValue is already implicitly castable to TypeX. Unnecessary explicit casting is noise in code, and can even decrease performance.

Example1

void Foo(int foo)
{
    var bar = (int)foo;
}

should be 🡻

void Foo(int foo)
{
    var bar = foo;
}

Example2

var bar = (int)Foo();

public int Foo()
{
    ...
}

should be 🡻

var bar = Foo();

public int Foo()
{
    ...
}