TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C# Coding Standard

Rule:  5@108Checked automatically with code checker

Synopsis:Do not 'shadow' a name in an outer scope
Severity Level:2
Category:Object lifecycle


Repeating a name that already occurs in an outer scope is seldom intended and may be surprising in maintenance, although the behaviour is well-defined.

int foo = something;

if (whatever)
	double foo = 12.34;	
        double anotherFoo = foo; // Violation.


In case a method parameter has the same name as a field then the following construction can be used: this.x = x

int foo = something;
public void SomeMethod(int foo)
	this.foo = foo; // No violation
        int anotherFoo = foo; // However, this again is a violation!