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 ...
随机推荐
- ad画fpc
得到新技能 后记: 实际情况,复杂很多pin的fpc 都是用cad画的.我明天学...
- runtime作用
1.发送消息 方法调用的本质,就是让对象发送消息. objc_msgSend,只有对象才能发送消息,因此以objc开头. 使用消息机制前提,必须导入#import <objc/message.h ...
- myeclipse2014 svn插件添加
http://blog.csdn.net/sushengmiyan/article/details/38342411
- linux命令:文件属性
Linux 文件的属性主要包括:节点.种类.权限模式.链接数量.所归属的用户和用户组.文件大小.最近访问或修改的时间等内容. 命令: ls -lih 输出: [root@localhost test] ...
- hdu1000,hdu1001,hdu1002,hdu1003
hdu1000 仅仅是为了纪念 #include <cstdio> int main() { int a,b; while (scanf("%d%d",&a,& ...
- Android自定义权限和使用权限
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 自定义权限,主要用于保护被赋予权限的组件.如无权限与有权限,正如public与private的对类保 ...
- C# 的各种排序
http://www.cnblogs.com/jiajiayuan/category/302446.html
- block中如何避免循环引用
使用 weak–strong dance 技术 block 可以直接引用 self,但是要非常小心地在 block 中引用 self.因为在 block 引用 self,可能会导致循环引用.如下例所示 ...
- REDIS 字典数据结构
对于REDIS来讲 其实就是一个字典结构,key ---->value 就是一个典型的字典结构 [当然 对于vaule来讲的话,有不同的内存组织结构 这是后话] 试想一个这样的存储场景: ...
- android库站点
图片加载库picasso:让本地图片.网络图片的加载变得如此简单. 引导页面的开源框架 guideshow自带小动画,但sdk要求18+ AppIntro界面很简约漂亮 circleindicator ...