List的FindIndex和ForEach
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的更多相关文章
- js数组中的find(), findIndex(), filter(), forEach(), some(), every(), map(), reduce()方法的详解和应用实例
1. find()与findIndex() find()方法,用于找出第一个符合条件的数组成员.它的参数是一个回调函数,所有数组成员依次执行该回调函数,直到找出第一个返回值为true的成员,然后返回该 ...
- js数组操作方法
数组的操作方法在js中可谓是诸子百家,各种某乱的方法让人眼花缭乱,有时候就会分不清什么是自带的什么是曾今写的api了 数组的增删 1 . push() , pop() 和 shift() unshi ...
- javascript(基础)_对数组的遍历方法总结(find, findIndex, forEach,)
一.前言 ...
- 数组的新方法 forEach some filter findIndex
forEach some filter findIndex这些都属于数组的新方法,都会对数组中的每一项,进行遍历,执行相关的操作: 只不过在循环的时候有些不一样 参考资料:https://wan ...
- 原生JS数组操作的6个函数 arr.forEach arr.map arr.filter arr.some arr.every arr.findIndex
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 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++ ...
- 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( ...
- forEach、map、filter、find、sort、some等易错点整理
一.常用方法解析 说起数组操作,我们肯定第一反应就是想到forEach().map().filter()等方法,下面分别阐述一下各方法的优劣. 1.forEach 1.1 基础点 forEac ...
- JavaScript数组forEach循环
JavaScript数组forEach循环 今天写JavaScript代码把forEach循环数组忘记写法了,在此记录一下以防止未来忘记. let a = [1, 2, 3]; a.forEach(f ...
随机推荐
- C#多线程开发中如何更新UI界面控件内容
子线程不能修改UI线程的状态(比如文本框里面的内容). 解决的办法是写一个用来更新文本框内容的函数,然后在Worker线程里面通过BeginInvoke来利用delegate调用这个函数更新文本框. ...
- SQL查询语句执行速度快,存储过程执行慢
今天一个生成10w条数据的存储过程执行了95s,但是单独执行SQL语句只需要28s,查资料后发现原来这是存储过程的机制导致的,也就是传说中的参数嗅探 网上的一段话: (1)可能是发生了参数嗅探,第一次 ...
- SQL-表的各种查查查
use Student gocreate table student1(code int,name varchar (20),sex char(10),tizhong decimal(18,1),ag ...
- ie9 placeholder兼容
.phcolor{ color:#999;}//css样式 function isPlaceholer(){ var input = document.createElement("inpu ...
- selected 刷新页面后selected选中的值保持不表(thinkphp 从控制器assign 传值到js)
昨晚解决select 刷新页面以后选择的值保持不变,要想让seleted不变,有两种思路, 1,在提交表单的时候,将所选择的option的属性设为checked . 2.将option的value或者 ...
- 库函数API和C语言汇编语言混合式编程
C语言代码内嵌汇编的方法: 在C语言文件中以如下格式加入汇编代码 __asm__( “汇编语句模板” :输出部分 :输入部分 :“破坏描述部分” ) asm可以由__asm__代替,为其别名. 可加上 ...
- Photoshop制作的海报修改~
经过几天的征求意见,感觉还是要重新制作,于是把颜色删减了不少 . 这次运用了蒙版和渐变,但感觉效果不太好.再改.. 后来觉得给人的单身感有点少.. 不知道感觉如何,但自己觉得比以前好看..
- ajax的status为201依然触发jquery的error事件的问题
昨天在调试一个ajax的时候发现,即使status是201,仍然会触发jquery的error事件.statusText是"parseerror". 通过在stackoverflo ...
- System Sounds: Alerts and Sound Effects
#include <AudioToolbox/AudioToolbox.h> #include <CoreFoundation/CoreFoundation.h> // Def ...
- 支持向量机 (SVM)分类器原理分析与基本应用
前言 支持向量机,也即SVM,号称分类算法,甚至机器学习界老大哥.其理论优美,发展相对完善,是非常受到推崇的算法. 本文将讲解的SVM基于一种最流行的实现 - 序列最小优化,也即SMO. 另外还将讲解 ...