Jon Jagger
jon@jaggersoft.com
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 17 Classesprevious at this levelnext at this level 17.5 Methodsprevious at this levelnext at this level 17.5.8 Method body Paragraph 11 The method-body of a method declaration consists of either a block or a semicolon. Paragraph 21 Abstract and external method declarations do not provide a method implementation, so their method bodies simply consist of a semicolon. 2 For any other method, the method body is a block (§15.2) that contains the statements to execute when that method is invoked. Paragraph 31 When the return type of a method is void, return statements (§15.9.4) in that method's body are not permitted to specify an expression. 2 If execution of the method body of a void method completes normally (that is, control flows off the end of the method body), that method simply returns to its caller. Paragraph 41 When the return type of a method is not void, each return statement in that method body must specify an expression of a type that is implicitly convertible to the return type. 2 The endpoint of the method body of a value-returning method must not be reachable. 3 In other words, in a value-returning method, control is not permitted to flow off the end of the method body. [Example: In the example
class A  
{  
   public int F() {}     // Error, return value required  
   public int G() {  
      return 1;  
   }  
   public int H(bool b) {  
      if (b) {  
         return 1;  
      }  
      else {  
         return 0;  
      }  
   }  
}  
the value-returning F method results in a compile-time error because control can flow off the end of the method body. The G and H methods are correct because all possible execution paths end in a return statement that specifies a return value. end example]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS