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. C语言程序设计第九次作业

    一.学习内容      本次课我们重点学习了怎样向函数传递数组,鉴于大家对函数和数组的理解和运用还存在一些问题,下面通过一些实例加以说明,希望同学们能够认真阅读和理解.      例1:火柴棍拼数字 ...

  2. Android深度探索--HAL与驱动开发----第三章读书笔记

    1. 什么是Git? Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理.Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开 ...

  3. 中秋时候做了一个ppt画图插件

    http://office.guanexcel.com/chart/chart.html PowerPoint里面简单的画图工具,输入数据选择图样即可插入到PPT中了

  4. line-height的一点粗浅认识

    line-height:有5种不同类型的单位. line-height: normal|inherit(继承)|%(百分比)|20px(像素值)|1.2(倍数); 将行高和字体大小结合: body { ...

  5. 手把手Maven搭建SpringMVC+Spring+MyBatis框架(超级详细版)

    手把手Maven搭建SpringMVC+Spring+MyBatis框架(超级详细版) SSM(Spring+SpringMVC+Mybatis),目前较为主流的企业级架构方案.标准的MVC设计模式, ...

  6. C#在Dictionary中使用枚举作为键

    Enum类型没有实现IEquatable接口,Dictionary中使用Enum作为键时,将发生装箱,使效率降低. 此时可用Dictionary中一个接收IEqualityComparer<T& ...

  7. 浅谈js的事件冒泡机制

    很多人都听说过,js的事件冒泡机制,其实,这个说法还是比较生动形象的,就是一个水泡在水底下,冒泡到水面的过程. 那js的事件冒泡机制呢,就是一个DOM树,一级一级向上冒的过程,最终是到document ...

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

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

  9. 【转】Native JavaScript Data-Binding

    原文转自:http://www.sellarafaeli.com/blog/native_javascript_data_binding Two-way data-binding is such an ...

  10. tinyxml一个优秀的C++ XML解析器

    读取和设置xml配置文件是最常用的操作,试用了几个C++的XML解析器,个人感觉TinyXML是使用起来最舒服的,因为它的API接口和Java的十分类似,面向对象性很好. TinyXML是一个开源的解 ...