C# 7 syntax for out parameters - CSharp Custom Type

CSharp examples for Custom Type:Method Parameter

Description

C# 7 syntax for out parameters

Demo Code

using static System.Console;
using System;/*from   w  ww. j  a  v  a  2 s .c om*/
using System.Collections.Generic;
class Program
{
   static void Main(string[] args)
   {
      int d = 10;
      int e = 20;
      WriteLine($"Before: d = {d}, e = {e}, f doesn't exist yet!");
      PassingParameters(d, ref e, out int f);
      WriteLine($"After: d = {d}, e = {e}, f = {f}");
   }
   public static void PassingParameters(int x, ref int y, out int z)
   {
      // out parameters cannot have a default AND must be initialized inside the method
      z = 99;
      x++;
      y++;
      z++;
   }
}

Result


Related Tutorials