#640 – Method Names that You Cannot Use

The C# compiler will sometimes generate new methods in the IL, as an implementation of a particular language element.

For example, assume that you define a Name property:

public string Name { get; set; }

The IL that is generated as the implementation of this property will include the two methods get_Name and set_Name.

Because the compiler generates methods named set_XYZ and get_XYZ, where XYZ is a property that you define, you cannot implement methods having these same names.

The full list of method names that you cannot use in your code is:

  • get_XYZset_XYZ  (if your class contains a property named XYZ)
  • get_Itemset_Item  (if your class defines an indexer with a matching parameter list)
  • Finalize  (if your class defines a destructor)
  • add_XYZ(T)remove_XYZ(T)  (if your class defines an event named XYZ of type T)
Advertisement