FindIndex和ForEach能接受一个delegate,用来定义查找规则太好用。

匿名函数,萌萌哒;Conditional("DEBUG")也是极好的。

读《C#本质论》

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics; namespace WindowsFormsApplication1
{
static class Program
{ class CADFileItem
{
public string GUID;
public string Name;
public string ModelClass;
public string ModelType;
public CADFileItem()
{
this.GUID = "0000-0000-0000-0000";
this.Name = "NoName";
this.ModelClass = "Aseembly";
this.ModelType = "FamilyMain";
}
[Conditional("DEBUG")]
public void WriteLine()
{
Debug.WriteLine(string.Format(@"GUID: {0}
Name: {1}
ModelClass: {2}
ModelType: {3}", GUID, Name, ModelClass, ModelType));
}
}
class FindCADFile
{
string findValue;
public FindCADFile(string val)
{
findValue = val;
} public bool FindGUID(CADFileItem file)
{
return file.GUID == findValue;
} public bool FindName(CADFileItem file)
{
return file.Name == findValue;
} public bool FindModelClass(CADFileItem file)
{
return file.ModelClass == findValue;
}
} /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{ List<CADFileItem> files = new List<CADFileItem>();
int intCount = ;
for (int u = ; u < intCount; ++u)
{
CADFileItem file = new CADFileItem();
file.GUID = file.GUID.Replace("-0000", "-000" + u);
file.Name = "CADFile" + u;
if(u== || u==intCount-)
file.ModelClass = "Part";
else
file.ModelClass = "Assembly";
file.WriteLine();
files.Add(file);
} int ret = files.FindIndex(new FindCADFile("0000-0002-0002-0002").FindGUID);
if (ret != -)
{
Debug.WriteLine("FindGUID--------");
files[ret].WriteLine();
}
ret = files.FindIndex(new FindCADFile("CADFile3").FindName);
if (ret != -)
{
Debug.WriteLine("FindName--------");
files[ret].WriteLine();
}
ret = files.FindIndex(new FindCADFile("Part").FindModelClass);
if (ret != -)
{
Debug.WriteLine("FindModelClass--------");
files[ret].WriteLine();
} Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

更多:http://msdn.microsoft.com/zh-cn/library/x1xzf2ca(v=vs.110).aspx

List的FindIndex和ForEach的更多相关文章

  1. js数组中的find(), findIndex(), filter(), forEach(), some(), every(), map(), reduce()方法的详解和应用实例

    1. find()与findIndex() find()方法,用于找出第一个符合条件的数组成员.它的参数是一个回调函数,所有数组成员依次执行该回调函数,直到找出第一个返回值为true的成员,然后返回该 ...

  2. js数组操作方法

    数组的操作方法在js中可谓是诸子百家,各种某乱的方法让人眼花缭乱,有时候就会分不清什么是自带的什么是曾今写的api了 数组的增删 1 . push() , pop()  和 shift() unshi ...

  3. javascript(基础)_对数组的遍历方法总结(find, findIndex, forEach,)

    一.前言                                                                                                ...

  4. 数组的新方法 forEach some filter findIndex

    forEach  some  filter  findIndex这些都属于数组的新方法,都会对数组中的每一项,进行遍历,执行相关的操作: 只不过在循环的时候有些不一样 参考资料:https://wan ...

  5. 原生JS数组操作的6个函数 arr.forEach arr.map arr.filter arr.some arr.every arr.findIndex

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. js中循环对比(for循环,foreach,for in,for of ,map)

    对空位的处理 for循环(不会忽略空位,标记undefined) var arr =[1,2,undefined,3,null,,7] for (let i=0;i<arr.length;i++ ...

  7. ES6-map、filter、find、findIndex讲解

    map方法:可以简单的理解为映射 var arr=[1,2,3,4]; console.log( arr.map((n)=>n*n) );//[1, 4, 9, 16] console.log( ...

  8. forEach、map、filter、find、sort、some等易错点整理

    一.常用方法解析   说起数组操作,我们肯定第一反应就是想到forEach().map().filter()等方法,下面分别阐述一下各方法的优劣. 1.forEach 1.1 基础点   forEac ...

  9. JavaScript数组forEach循环

    JavaScript数组forEach循环 今天写JavaScript代码把forEach循环数组忘记写法了,在此记录一下以防止未来忘记. let a = [1, 2, 3]; a.forEach(f ...

随机推荐

  1. linux下内存泄露检测工具Valgrind介绍

    目前在linux开发一个分析实时路况的应用程序,在联合测试中发现程序存在内存泄露的情况. 这下着急了,马上就要上线了,还好发现了一款Valgrind工具,完美的解决了内存泄露的问题. 推荐大家可以使用 ...

  2. js字符拼接

    for (var j = 0; j < 9; j++) { eval("if (datas[i].b" + j + " == '1') { b[j-1] = 1; ...

  3. 面向对象to1

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. freemarker string= null

    在java代码中经常会出现以下代码: String name; …………………… if(null == name || name.length == 0){ return; } 这行代码用freema ...

  5. [转]python问题:IndentationError:expected an indented block错误解决

    分类: python学习笔记2012-07-07 17:59 28433人阅读 评论(4) 收藏 举报 python语言 原文地址:http://hi.baidu.com/delinx/item/17 ...

  6. CentOS 7 网络配置工具

    之前在CentOS 6下编辑网卡,直接使用setup工具就可以了. 但在新版的CentOS 7里,setuptool已经没有网络编辑组件了,取而代之的是NetworkManager Text User ...

  7. adb获取不了设备List of devices attached

    方法/步骤: 首先找到手机的安装完之后的“设备的硬件id”,第一步右击我的电脑,然后找到设备管理器打开. 在设备管理器中,找到ADB driver然后点开. 然后在详细信息中,点开硬件ID,查看到我的 ...

  8. 使用 WinAppDeployCmd 部署Win10 App 到移动设备

    WinAppDeployCmd是目前微软提供的Win10 App 部署工具,它和以前的Windows Phone Application Deployment 部署工具有所不同的是,WinAppDep ...

  9. Linux mint 18版本开启SSH服务

    linux mint 18版本默认是没有安装ssh server的 需要手动安装 安装ssh server: 此命令需要联网,会自动下载安装 安装之后看是否开始了ssh, 看到ssh-agent 和s ...

  10. C#串口通讯实例

    本文参考<C#网络通信程序设计>(张晓明  编著) 程序界面如下图: 参数设置界面代码如下: using System; using System.Collections.Generic; ...