Methods return a value to the calling routine using this form of return:
return value;
value is the value returned.
using System; class MainClass { public static int GetHour() { return 123; } static void Main() { Console.WriteLine("Hour: {0}", GetHour()); } }
Hour: 123
7.7.Method Return | ||||
7.7.1. | Return int from function | |||
7.7.2. | Return an object | |||
7.7.3. | Use a class factory | |||
7.7.4. | Return an array | |||
7.7.5. | How to define methods that return a value and accept parameters | |||
7.7.6. | Methods That Return a Value and Accept Parameters |