output parameters in C#

A parameter declared with an out modifier is an output parameter. Listing given below shows the use of the output parameter.


Example of Output Parameters

Code Snippet
  1. using System;
  2. namespace Ch01
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             int x;
  9.             WithOutInParameter(out x);
  10.             Console.WriteLine(x);           /* 100 */
  11.         }
  12.         static void WithOutInParameter(out int a)
  13.         { a = 100; }
  14.     }
  15. }


This program will produce the output:
100

Post a Comment