CA2223: Members should differ by more than return type
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at CA2223: Members should differ by more than return type.
TypeName|MembersShouldDifferByMoreThanReturnType|
|CheckId|CA2223|
|Category|Microsoft.Usage|
|Breaking Change|Breaking|
Two public or protected members have signatures that are identical except for return type.
Although the common language runtime permits the use of return types to differentiate between otherwise identical members, this feature is not in the Common Language Specification, nor is it a common feature of .NET programming languages. When members differ only by return type, developers and development tools might not correctly distinguish between them.
To fix a violation of this rule, change the design of the members so that they are unique based only on their names and parameter types, or do not expose the members.
Do not suppress a warning from this rule.
The following example, in Microsoft intermediate language (MSIL), shows a type that violates this rule. Notice that this rule cannot be violated by using C# or Visual Basic .NET.
.namespace UsageLibrary
{
.class public auto ansi beforefieldinit ReturnTypeTest
extends [mscorlib]System.Object
{
.method public hidebysig instance int32
AMethod(int32 x) cil managed
{
// Code size 6 (0x6)
.maxstack 1
.locals init (int32 V_0)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: br.s IL_0004
IL_0004: ldloc.0
IL_0005: ret
} // end of method ReturnTypeTest::AMethod
.method public hidebysig instance string
AMethod(int32 x) cil managed
{
// Code size 10 (0xa)
.maxstack 1
.locals init (string V_0)
IL_0000: ldstr "test"
IL_0005: stloc.0
IL_0006: br.s IL_0008
IL_0008: ldloc.0
IL_0009: ret
} // end of method ReturnTypeTest::AMethod
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 1
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method ReturnTypeTest::.ctor
} // end of class ReturnTypeTest
} // end of namespace UsageLibrary