Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    The class A with a DoAdd method - both out and params.Lecture 5 - slide 27 : 29
Program 1
using System;

public class A{
  private int a, b, c;
  private int r;

  public A(){
    a = 1; b = 2; c = 3;
  }

  public void DoAdd(out int v, params int[] iv){  
    v = 0;  
    foreach(int i in iv)
      v += i;
  }
 
  public override string ToString(){
    return String.Format("{0} {1} {2}. {3}", a, b, c, r);
  }

  public void Go(){
    Console.WriteLine("{0}", this);

    DoAdd(out r, a, b, c);  
    Console.WriteLine("{0}", this);

    DoAdd(out r, a, b, c, a, b, c);  
    Console.WriteLine("{0}", this);

    DoAdd(out r); 
    Console.WriteLine("{0}", this);
  }    

  public static void Main(){
    new A().Go();
  }
}
 
 
 
 
 
 
 
 
 
 
Two formal parameters: An out and a parameter array.
This initialization is necessary!
 
 
 
 
 
 
 
 
 
 
 
Passes a+b+c out via r.
 
 
Passes a+b+c+a+b+c out via r.
 
 
Passes 0 out via r.