In some languages, a function must be declared before use. This is not necessary in C#. For example, we could rewrite the previous program, so that "Main" is the first function and "double" is after it, and it will still compile and run in the same way:
/*---------------------------*/
/* C# Example #55: */
/* example55.cs */
/* */
/* Function after Main */
/* */
/* Intro to C#, */
/* Nacho Cabanes */
/*---------------------------*/
using System;
public class Example55
{
public static void Main()
{
int n = 5;
Console.WriteLine("n is {0}", n);
double(ref n);
Console.WriteLine("Now n is {0}", n);
}
public static void double(ref int x) {
Console.WriteLine(" The received value is
{0}", x);
x = x * 2;
Console.WriteLine(" and now it is
{0}", x);
}
}
No comments:
Post a Comment