#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)

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: