Total .NET Analyzer Rule Documentation  

MemberGlobalConflict Rule

Avoid using the same name for members and classes.

Remarks

Avoid having identical member and class names. Although the compiler allows classes and members to be named identically, doing this creates code that is difficult to understand and maintain. For example, the following code contains a subroutine with the same name as the class:


' VB
Class Customer
Sub Customer()

End Sub
End Class

// C#
class Customer
{
class CustomerID
{
static void Customer()
{
}
}
}


In Visual Basic, variables can also conflict with Module declarations. For example:

Public Class Class1
Sub test()
Dim CustomerID As Integer
End Sub
End Class

Public Module MainMod
Dim CustomerID As Integer
End Module


Even with very short examples, identical member and class names create very confusing code.

Resolution

To make the code easier to understand, rename the field or the class to be unique. For instance, the code example above could be revised to the following:

' VB
' VB
Class CustomerInformation
Sub CreateCustomerID()

End Sub
End Class

// C#
class CustomerInformation
{
class CustomerID
{
static void CreateCustomer()
{
}
}
}

See Also