刚学习程序,感觉写代码 很有意思,所以把自己的感悟写下来啦,第一次写博客,可能是菜鸟中的菜鸟  时间久了,相信就会写的很好哦!

for和 foreach 的数组遍历 比较

很简单的程序,不解释啦!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ int[] nums = { 3, 5, 99, 23, 53, 88 }; //定义数组
int max = 0; for (int i = 0; i < nums.Length; i++) //for遍历数组
{
if (nums[i] > max)
{
max = nums[i];
}
}
Console.WriteLine("for遍历数组demo:" + max);
Console.WriteLine("====================================================");
foreach (var p in nums) //使用foreach 遍历
{
if (p > max)
{
max = p;
} }
Console.WriteLine("foreach遍历数组demo:"+max); } }
}

   结果为:

最新文章

  1. RS-232, RS-422, RS-485 Serial Communication General Concepts(转载)
  2. Scala:没有continue,break怎么办?
  3. 模拟java.util.Collection一些简单的用法
  4. Brackets(bestcoder)
  5. JavaScript中in操作符(for..in)、Object.keys()和Object.getOwnPropertyNames()的区别
  6. Android IOS WebRTC 音视频开发总结(十)-- webrtc入门002
  7. 两款较好的Web前端性能测试工具
  8. Objective-C 学习笔记(1)
  9. 防止跨域(jsonp详解)
  10. 关于URL 解码, 编码
  11. wxPython学习笔记(二)
  12. 微软推荐的Get a code signing certificate流程和链接
  13. 表设计与SQL优化
  14. table 中的td 字段超长,超过部分用....表示
  15. 主席树初步 HDU2665的区间第k小
  16. day001-html知识点总结(二)不常见但很重要的元素汇总
  17. NameError: name &#39;messagebox&#39; is not defined 错误处理
  18. 安装supervisord
  19. 【安卓开发】Layout Inflation不能这么用
  20. Angular 中的数据交互(get jsonp post)

热门文章

  1. C main
  2. mongo导出导入
  3. PAT乙级 1028. 人口普查(20)
  4. js获取单选框radio的值
  5. 【GDI+】 线段 文字 定位的问题
  6. 视频处理控件TVideoGrabber中如何混合多个视频源(1)
  7. iOS 解决的问题
  8. html5 canvas 笔记一(基本用法与绘制图形)
  9. IE6不支持CSS的属性选择器
  10. 【JQGRID DOCUMENTATION】.学习笔记.1.安装jqGrid