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. TOMCAT运行一段时间后网页无响应或连不上,TOMCAT无错误日志

    解决方法:修改 tomcat 的 java options 参数1)增加java options参数-Xmn384m-XX:MaxPermSize=128m-XX:+UseConcMarkSweepG ...

  2. iOS学习之下拉刷新、上拉加载

    http://blog.csdn.net/mx_xuanxiao/article/details/50595370

  3. C++中explicit关键字的使用

    看书看到了explicit关键字,就来做个笔记,讲得比较明白,比较浅. 在C++中,我们有时可以将构造函数用作自动类型转换函数.但这种自动特性并非总是合乎要求的,有时会导致意外的类型转换,因此,C++ ...

  4. Log4j快速使用精简版

    Log4j快速使用精简版 1.导入log4j-1.2.17.jar包 2.在src根目录下创建log4j.properties文件 log4j.rootLogger=INFO, CONSOLE, FI ...

  5. JavaScript数组模拟栈和队列

    *栈和队列:js中没有真正的栈和队列的类型              一切都是用数组对象模拟的 栈:只能从一端进出的数组,另一端封闭       FILO   何时使用:今后只要仅希望数组只能从一端进 ...

  6. window 下如何安装ghost博客

    1.安装nodejs # Node v0.12.x and v4.2+ LTS - supported 我本地安装的是4.2 安装其他版本可能提示系统不兼容 2.安装mysql 3.安装bower 4 ...

  7. software_testing_work2_question1(改)_edition

    由于上个版本问题多多,而且测试情况略有呵呵,于是想想还是默默的改进了一个版本. input类 首先呢,是作为输入项的实体类input. 对比之前的版本,新版本(姑且称其为edition2)加强了ope ...

  8. mysql5.7 慢查底里失败的原因

    正确配置: log_output          = FILEslow-query-log = on slow_query_log_file ="D:/MySQL5.7/data/slow ...

  9. mac平台多个php版本快速切换

    mac平台多个php版本快速切换 要求所有php版本都是由brew安装 使用brew安装php多版本方法 # brew install php56 # brew install php70 安装切换工 ...

  10. ListView到顶部不可再拉

    ListView到顶部不可再拉,主要针对魅族.索爱等手机: 如果你的程序针对的是2.3及以上版本,可以直接调用AbsListView的setOverScrollMode方法来解决这个问题. 如果还要兼 ...