函數見 return 就返回:
using System;
class MyClass
{
static int Math(int x, int y)
{
return x + y;
return x * y; /* 執行不了這句 */
}
static void Main()
{
Console.WriteLine(Math(3,4)); //7
Console.ReadKey();
}
}
數組參數:
using System;
class MyClass
{
static int ArrMax(int[] arr)
{
int max = arr[0];
for (int i = 1; i < arr.Length; i++)
if (arr[i] > max) max = arr[i];
return max;
}
static void Main()
{
int[] ns = { 1,2,3,4,5,4,3,2,1 };
Console.WriteLine(ArrMax(ns)); //5
Console.ReadKey();
}
}