求和怎么弄
我想在C#中实现几个X值的求和,怎么做?
/// <summary> /// 返回相加 /// </summary> /// <param name="s"></param> /// <returns></returns> public int GetSum(int[] s) { int result = 0; for(int i=0;i<s.Length;i++) { result += s[i]; } return result; }
E.G: int[] abc={1,2,3,4,5,6}; MessageBox.Show(GetSum(abc).ToString());