Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    Demonstration of simple functions in C#.Lecture 2 - slide 15 : 43
Program 1
/* Right, Wrong */

using System;


/* 
public int Increment(int i){   
  return i + 1;                
}                              

public void Main (){
  int i = 5,
      j = Increment(i);
  Console.WriteLine("i and j: {0}, {1}", i, j);
} // end Main     
*/

public class FunctionDemo {

  public static void Main (){
    SimpleFunction();
  }

  public static void SimpleFunction(){   
    int i = 5,
        j = Increment(i);
    Console.WriteLine("i and j: {0}, {1}", i, j);
  }

  public static int Increment(int i){
    return i + 1;
  }    
}
 
 
 
 
 
 
Functions are not allowed here.
A namespace can only contain types
and namespace declarations.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
A simple function which calls increment.