<?xml version="1.0"?>
<clause number="17.5" title="Methods">
  <paragraph>A method is a member that implements a computation or action that can be performed by an object or class. Methods are declared using method-declarations: <grammar_production><name><non_terminal where="17.5">method-declaration</non_terminal></name> : <rhs><non_terminal where="17.5">method-header</non_terminal><non_terminal where="17.5">method-body</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="17.5">method-header</non_terminal></name> : <rhs><non_terminal where="24.2">attributes</non_terminal><opt/><non_terminal where="17.5">method-modifiers</non_terminal><opt/><non_terminal where="17.5">return-type</non_terminal><non_terminal where="17.6">member-name</non_terminal><terminal>(</terminal><non_terminal where="17.5.1">formal-parameter-list</non_terminal><opt/><terminal>)</terminal></rhs></grammar_production><grammar_production><name><non_terminal where="17.5">method-modifier</non_terminal>s</name> : <rhs><non_terminal where="17.5">method-modifier</non_terminal></rhs><rhs><non_terminal where="17.5">method-modifiers</non_terminal><non_terminal where="17.5">method-modifier</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="17.5">method-modifier</non_terminal></name> : <rhs><keyword>new</keyword></rhs><rhs><keyword>public</keyword></rhs><rhs><keyword>protected</keyword></rhs><rhs><keyword>internal</keyword></rhs><rhs><keyword>private</keyword></rhs><rhs><keyword>static</keyword></rhs><rhs><keyword>virtual</keyword></rhs><rhs><keyword>sealed</keyword></rhs><rhs><keyword>override</keyword></rhs><rhs><keyword>abstract</keyword></rhs><rhs><keyword>extern</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="17.5">return-type</non_terminal></name> : <rhs><non_terminal where="11">type</non_terminal></rhs><rhs><keyword>void</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="17.6">member-name</non_terminal></name> : <rhs><non_terminal where="9.4.2">identifier</non_terminal></rhs><rhs><non_terminal where="11.2">interface-type</non_terminal><terminal>.</terminal><non_terminal where="9.4.2">identifier</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="17.5">method-body</non_terminal></name> : <rhs><non_terminal where="15.2">block</non_terminal></rhs><rhs><terminal>;</terminal></rhs></grammar_production></paragraph>
  <paragraph>A <non_terminal where="17.5">method-declaration</non_terminal> may include a set of attributes (<hyperlink>24</hyperlink>) and a valid combination of the four access modifiers (<hyperlink>17.2.3</hyperlink>), the new (<hyperlink>17.2.2</hyperlink>), static (<hyperlink>17.5.2</hyperlink>), virtual (<hyperlink>17.5.3</hyperlink>), override (<hyperlink>17.5.4</hyperlink>), sealed (<hyperlink>17.5.5</hyperlink>), abstract (<hyperlink>17.5.6</hyperlink>), and extern (<hyperlink>17.5.7</hyperlink>) modifiers. </paragraph>
  <paragraph>A declaration has a valid combination of modifiers if all of the following are true: <list><list_item> The declaration includes a valid combination of access modifiers (<hyperlink>17.2.3</hyperlink>). </list_item><list_item> The declaration does not include the same modifier multiple times. </list_item><list_item> The declaration includes at most one of the following modifiers: static, virtual, and override. </list_item><list_item> The declaration includes at most one of the following modifiers: new and override. </list_item><list_item> If the declaration includes the abstract modifier, then the declaration does not include any of the following modifiers: static, virtual, or extern. </list_item><list_item> If the declaration includes the private modifier, then the declaration does not include any of the following modifiers: virtual, override, or abstract. </list_item><list_item> If the declaration includes the sealed modifier, then the declaration also includes the override modifier. </list_item></list></paragraph>
  <paragraph>The <non_terminal where="17.5">return-type</non_terminal> of a method declaration specifies the type of the value computed and returned by the method. The <non_terminal where="17.5">return-type</non_terminal> is <keyword>void</keyword> if the method does not return a value. </paragraph>
  <paragraph>The <non_terminal where="17.6">member-name</non_terminal> specifies the name of the method. Unless the method is an explicit interface member implementation (<hyperlink>20.4.1</hyperlink>), the <non_terminal where="17.6">member-name</non_terminal> is simply an identifier. For an explicit interface member implementation, the <non_terminal where="17.6">member-name</non_terminal> consists of an <non_terminal where="11.2">interface-type</non_terminal> followed by a &quot;.&quot; and an identifier. </paragraph>
  <paragraph>The optional <non_terminal where="17.5.1">formal-parameter-list</non_terminal> specifies the parameters of the method (<hyperlink>17.5.1</hyperlink>). </paragraph>
  <paragraph>The <non_terminal where="17.5">return-type</non_terminal> and each of the types referenced in the <non_terminal where="17.5.1">formal-parameter-list</non_terminal> of a method must be at least as accessible as the method itself (<hyperlink>10.5.4</hyperlink>). </paragraph>
  <paragraph>For abstract and extern methods, the <non_terminal where="17.5">method-body</non_terminal> consists simply of a semicolon. For all other methods, the <non_terminal where="17.5">method-body</non_terminal> consists of a block, which specifies the statements to execute when the method is invoked. </paragraph>
  <paragraph>The name and the formal parameter list of a method define the signature (<hyperlink>10.6</hyperlink>) of the method. Specifically, the signature of a method consists of its name and the number, modifiers, and types of its formal parameters. The return type is not part of a method's signature, nor are the names of the formal parameters. </paragraph>
  <paragraph>The name of a method must differ from the names of all other non-methods declared in the same class. In addition, the signature of a method must differ from the signatures of all other methods declared in the same class. </paragraph>
</clause>
