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.1 Method parametersprevious at this levelnext at this level 17.5.1.3 Output parameters Paragraph 11 A parameter declared with an out modifier is an output parameter. 2 Similar to a reference parameter, an output parameter does not create a new storage location. 3 Instead, an output parameter represents the same storage location as the variable given as the argument in the method invocation. Paragraph 21 When a formal parameter is an output parameter, the corresponding argument in a method invocation must consist of the keyword out followed by a variable-reference (§12.3.3) of the same type as the formal parameter. 2 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 31 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 41 Every output parameter of a method must be definitely assigned before the method returns. Paragraph 51 Output parameters are typically used in methods that produce multiple return values. [Example: For example:
using System;  
class Test  
{  
   static void SplitPath(string path, out string dir, out string name) {  
      int i = path.Length;  
      while (i > 0) {  
         char ch = path[i - 1];  
         if (ch == '\\' || ch == '/' || ch == ':') break;  
         i--;  
      }  
      dir = path.Substring(0, i);  
      name = path.Substring(i);  
   }  
   static void Main() {  
      string dir, name;  
      SplitPath("c:\\Windows\\System\\hello.txt", out dir, out name);  
      Console.WriteLine(dir);  
      Console.WriteLine(name);  
   }  
}  
The example produces the output:
c:\Windows\System\  
hello.txt  
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]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS