C# Demonstration of Methods (.Net)

See below a procedure and a function with one parameter each. When calling a method, you must remember to append a pair of empty brackets to the identifier if the routine does not take a parameter.

using System;

namespace routines
{
  static class Program
  {
    public static void Greeting(String msg)  // procedure has void return type
    {
      Console.WriteLine(msg);
    }

    public static Double CircleArea(Double radius) // function
    {
      return 3.142 * radius * radius;
    }

    public static void Main(string[] args)
    {
      Greeting("Hello");
      Double area = CircleArea(2.18);
      Console.WriteLine("Area to 2 dp: {0:0.00}", area);
      Console.ReadLine();
    }
  }
}

Output:
Hello
Area to 2 dp: 14.93

Programming - a skill for life!

C# Demonstrations of I/O, arrays, methods, classes, loops, enums, pointers, file handling, Firebird databases, LINQ and drawing on a form