博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
参数为数组的方法
阅读量:4610 次
发布时间:2019-06-09

本文共 1392 字,大约阅读时间需要 4 分钟。

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace ConsoleApplication7 8 { 9     class Program10     {11         static void Main(string[] args)12         {13             int sum1;14             int[] intArray = { 1,2,3};15             sum1 = Test(intArray);16             Console.WriteLine("数组的和是:{0}",sum1);17             Console.ReadKey();18         }19         public static int Test(int[] numbers)20         {21             int sum = 0;22             for (int i = 0; i < numbers.Length; i++)23             {24                 sum += numbers[i];25             }26             return sum;27         }28     }29 }

 如果参数只是传入数组的个别元素,则可以这个样写:

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace ConsoleApplication7 8 { 9     class Program10     {11         static void Main(string[] args)12         {13             int sum1;14             int[] intArray = { 1,2,3};15             sum1 = Test(intArray[0],intArray[2]);16             Console.WriteLine("数组的和是:{0}",sum1);17             Console.ReadKey();18         }19         public static int Test(int a, int b)20         {21             int sum = a + b;22             return sum;23         }24     }25 }

 

转载于:https://www.cnblogs.com/start-from-scratch/p/5056476.html

你可能感兴趣的文章
30、git 使用
查看>>
iOS网络-02-数据解析(JSON与XML)
查看>>
python列表求和的几种等效电路
查看>>
Luogu P3393 逃离僵尸岛
查看>>
Flatten Binary Tree to Linked List
查看>>
Edit Distance
查看>>
软件工程第一次作业补充
查看>>
N76E003---输入捕获
查看>>
poj 1094 Sorting It All Out(拓扑排序)
查看>>
acdream B - 郭式树 (水题 卡cin,cout, 卡LL)
查看>>
BMP图像格式
查看>>
python的匿名函数lambda解释及用法
查看>>
c#遍历Dictionary使用KeyValuePair
查看>>
defineProperties属性的运用==数据绑定
查看>>
关于 IOS 发布的点点滴滴记录(一)
查看>>
《EMCAScript6入门》读书笔记——14.Promise对象
查看>>
CSS——水平/垂直居中
查看>>
Eclipse连接mysql数据库jdbc下载(图文)
查看>>
Python中Selenium的使用方法
查看>>
三月23日测试Fiddler
查看>>