disable broken tests on net_4_0
[mcs.git] / docs / ecma334 / 8.7.3.xml
blobf07db6a1849d15fd0d5da9fcfc9e31dcf3435017
1 <?xml version="1.0"?>
2 <clause number="8.7.3" title="Methods" informative="true">
3   <paragraph>A method is a member that implements a computation or action that can be performed by an object or class. Methods have a (possibly empty) list of formal parameters, a return value (unless the method's <non_terminal where="17.5">return-type</non_terminal> is <keyword>void</keyword>), and are either static or non-static. Static methods are accessed through the class. Non-static methods, which are also called instance methods, are accessed through instances of the class. The example <code_example><![CDATA[
4 using System;  
5 public class Stack  
6 {  
7    public static Stack Clone(Stack s) {...}  
8    public static Stack Flip(Stack s) {...}  
9    public object Pop() {...}  
10    public void Push(object o) {...}  
11    public override string ToString() {...}  
12    ...  
13 }  
14 class Test  
15 {  
16    static void Main() {  
17       Stack s = new Stack();  
18       for (int i = 1; i < 10; i++)  
19       s.Push(i);  
20       Stack flipped = Stack.Flip(s);  
21       Stack cloned = Stack.Clone(s);  
22       Console.WriteLine("Original stack: " + s.ToString());  
23       Console.WriteLine("Flipped stack: " + flipped.ToString());  
24       Console.WriteLine("Cloned stack: " + cloned.ToString());  
25    }  
26 }  
27 ]]></code_example>shows a Stack that has several static methods (Clone and Flip) and several instance methods (Pop, Push, and ToString). </paragraph>
28   <paragraph>Methods can be overloaded, which means that multiple methods may have the same name so long as they have unique signatures. The signature of a method consists of the name of the method and the number, modifiers, and types of its formal parameters. The signature of a method does not include the return type. The example <code_example><![CDATA[
29 using System;  
30 class Test  
31 {  
32    static void F() {  
33       Console.WriteLine("F()");  
34    }  
35    static void F(object o) {  
36       Console.WriteLine("F(object)");  
37    }  
38    static void F(int value) {  
39       Console.WriteLine("F(int)");  
40    }  
41    static void F(ref int value) {  
42       Console.WriteLine("F(ref int)");  
43    }  
44    static void F(int a, int b) {  
45       Console.WriteLine("F(int, int)");  
46    }  
47    static void F(int[] values) {  
48       Console.WriteLine("F(int[])");  
49    }  
50    static void Main() {  
51       F();  
52       F(1);  
53       int i = 10;  
54       F(ref i);  
55       F((object)1);  
56       F(1, 2);  
57       F(new int[] {1, 2, 3});  
58    }  
59 }  
60 ]]></code_example>shows a class with a number of methods called F. The output produced is <code_example><![CDATA[
61 F()  
62 F(int)  
63 F(ref int)  
64 F(object)  
65 F(int, int)  
66 F(int[])  
67 ]]></code_example></paragraph>
68 </clause>