using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Demo
{
class Program
{
static int MaxValue(int[] intArray)
{
int maxVal = intArray[0];
for (int i = 1;i<intArray.Length;i++)
{
if (intArray[i] > maxVal)
{
maxVal = intArray[i];
}
}
return maxVal;
} static void Main(string[] args)
{
int[] myArray = { 1, 3, 5, 8, 2, 10, 9, 100, 40 };
int maxVal = MaxValue(myArray);
Console.WriteLine("最大值为:{0}",maxVal);
Console.ReadKey();
}
}
}

params传参

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Demo
{
class Program
{
static int MaxValue(params int[] intArray)
{
int maxVal = intArray[0];
for (int i = 1;i<intArray.Length;i++)
{
if (intArray[i] > maxVal)
{
maxVal = intArray[i];
}
}
return maxVal;
} static void Main(string[] args)
{
int maxVal = MaxValue(1,3,4,100,200,3);
Console.WriteLine("最大值为:{0}",maxVal);
Console.ReadKey();
}
}
}

out使用,类似于callback。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Demo
{
class Program
{
static int MaxValue(out int maxIndex,params int[] intArray)
{
int maxVal = intArray[0];
maxIndex = 0;
for (int i = 1;i<intArray.Length;i++)
{
if (intArray[i] > maxVal)
{
maxVal = intArray[i];
maxIndex = i;
}
}
return maxVal;
} static void Main(string[] args)
{
int maxIndex;
int maxVal = MaxValue(out maxIndex,1,3,4,100,200,3);
Console.WriteLine("最大值为:{0}",maxVal);
Console.WriteLine("索引为:{0}", maxIndex);
Console.ReadKey();
}
}
}

最新文章

  1. Linux下安装Hadoop完全分布式(Ubuntu12.10)
  2. 安卓---Toast工具类,有点懒
  3. Java数据结构之回溯算法的递归应用迷宫的路径问题
  4. 获取Executor提交的并发执行的任务返回结果的两种方式/ExecutorCompletionService使用
  5. thinkphp 3.2 单入口 多模块 不能加载index控制器问题
  6. 高级UNIX环境编程11 线程
  7. 重复数据删除(De-duplication)技术研究(SourceForge上发布dedup util)
  8. mysql5.7.17安装问题
  9. [iOS]C语言技术视频-10-指针变量
  10. 20170410 --- Linux备课资料 --- vim的使用
  11. C# MessageBox.Show每隔3秒自动关闭
  12. php -- 断点调试 之 选择合适的xdebug
  13. C/C++基础----标准库几个工具库tuple,bitset,正则表达式,随机数,IO库
  14. css:清楚浮动
  15. [转]使用spring中的@Transactional注解时,可能需要注意的地方
  16. 使用vue模拟购物车小球动画
  17. scrapy定制爬虫-爬取javascript——乾颐堂
  18. ONTAK 2010 aut
  19. 设计模式03: Builder 生成器模式(创建型模式)
  20. Unicode(UTF-8, UTF-16)令人混淆的概念----我看完了 不错

热门文章

  1. 33.unique_ptr独享内存智能指针
  2. BZOJ 2124 线段树维护hash值
  3. POJ 3277 线段树+扫描线
  4. HDFS的底层原理
  5. 机器学习(七) PCA与梯度上升法 (下)
  6. orac
  7. yii2.0缓存篇之片段缓存
  8. NodeJS学习笔记 (22)全局对象-global
  9. iOS开发——国际化支持Localizable.strings
  10. JZOJ5821手机信号