disable broken tests on net_4_0
[mcs.git] / docs / ecma334 / 17.5.1.3.xml
blob77bf225f39c6365bb21efe03e1b9730aee5407b2
1 <?xml version="1.0"?>
2 <clause number="17.5.1.3" title="Output parameters">
3   <paragraph>A parameter declared with an out modifier is an output parameter. Similar to a reference parameter, an output parameter does not create a new storage location. Instead, an output parameter represents the same storage location as the variable given as the argument in the method invocation. </paragraph>
4   <paragraph>When a formal parameter is an output parameter, the corresponding argument in a method invocation must consist of the keyword out followed by a <non_terminal where="12.4">variable-reference</non_terminal> (<hyperlink>12.3.3</hyperlink>) of the same type as the formal parameter. A variable need not be definitely assigned before it can be passed as an output parameter, but following an invocation where a variable was passed as an output parameter, the variable is considered definitely assigned. </paragraph>
5   <paragraph>Within a method, just like a local variable, an output parameter is initially considered unassigned and must be definitely assigned before its value is used. </paragraph>
6   <paragraph>Every output parameter of a method must be definitely assigned before the method returns. </paragraph>
7   <paragraph>Output parameters are typically used in methods that produce multiple return values. <example>[Example: For example: <code_example><![CDATA[
8 using System;  
9 class Test  
10 {  
11    static void SplitPath(string path, out string dir, out string name) {  
12       int i = path.Length;  
13       while (i > 0) {  
14          char ch = path[i - 1];  
15          if (ch == '\\' || ch == '/' || ch == ':') break;  
16          i--;  
17       }  
18       dir = path.Substring(0, i);  
19       name = path.Substring(i);  
20    }  
21    static void Main() {  
22       string dir, name;  
23       SplitPath("c:\\Windows\\System\\hello.txt", out dir, out name);  
24       Console.WriteLine(dir);  
25       Console.WriteLine(name);  
26    }  
27 }  
28 ]]></code_example></example></paragraph>
29   <paragraph>
30     <example>The example produces the output: <code_example><![CDATA[
31 c:\Windows\System\  
32 hello.txt  
33 ]]></code_example></example>
34   </paragraph>
35   <paragraph>
36     <example>Note that the dir and name variables can be unassigned before they are passed to SplitPath, and that they are considered definitely assigned following the call. end example]</example>
37   </paragraph>
38 </clause>