1。可变数量参数(相同类型)作为单个逻辑传给方法
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace @params { class Program { static void Main(string[] args) { double average = CalAverage(123.1,12,3.2,56); double[] data = {3.2,5.6,33.3 }; Console.WriteLine(average); double s = CalAverage(data); Console.WriteLine(s); } static double CalAverage(params double[] values) { double sum = 0; if (values.Length == 0) return sum; for (int i = 0; i < values.Length; i++) sum += values[i]; return (sum / values.Length);
} } }