IEnumerable<Attribute> keys = p.GetCustomAttributes().ToList();
  var data1 = data.Where(n => n.Name.Contains(search)).ToList();
  if (data1.Count == 0)

//MSDN例子

using System;
using System.Windows.Forms;
using System.Collections; namespace Exceltest
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
} private void Form3_Load(object sender, EventArgs e)
{
MessageBox.Show("");
Person[] peopleArray = new Person[]
{
new Person("John", "Smith"),
new Person("Jim", "Johnson"),
new Person("Sue", "Rabon"),
};
var ss = new People(peopleArray); //创建一个对象,这个对象_people属性是一个数组 People peopleList = new People(peopleArray);
foreach (Person p in peopleList) //如果不集成IEnumerable,对象将无法使用foreach
Console.WriteLine(p.firstName + " " + p.lastName);
}
} public class Person //人,个人
{
public Person(string fName, string lName)
{
this.firstName = fName;
this.lastName = lName;
} //构造方法
public string firstName;
public string lastName;
} public class People : IEnumerable //人,大家
{
private Person[] _people; //定义一个个人数组 public People(Person[] pArray) //构造函数需要传递过来一个数组 /////数组传递到people中
{
_people = new Person[pArray.Length]; //初始化数组的范围, for (int i = ; i < pArray.Length; i++)
{
_people[i] = pArray[i];
}
} IEnumerator IEnumerable.GetEnumerator() // 集成必须要实现该接口
{
PeopleEnum ss = new PeopleEnum(_people); return new PeopleEnum(_people); //返回
}
} public class PeopleEnum : IEnumerator
{
public Person[] _people; // Enumerators are positioned before the first element
// until the first MoveNext() call.
int position = -; public PeopleEnum(Person[] list)
{
_people = list;
} public bool MoveNext()
{
position++;
return (position < _people.Length);
} public void Reset()
{
position = -;
} public object Current
{
get
{
try
{
return _people[position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
}
}

C# 获取 IEnumerable 集合的个数的更多相关文章

  1. 【转载】 C#中使用Count方法获取List集合中符合条件的个数

    很多时候操作List集合的过程中,我们需要根据特定的查询条件,获取List集合中有多少个实体对象符合查询条件,例如一批产品的对象List集合,如果这批产品的不合格数量大于10则重点备注.在C#中可以自 ...

  2. Atitit利用反射获取子类 集合 以及继承树

    Atitit利用反射获取子类 集合 以及继承树 想从父类往下找子类的确是不可能的,要知道只要类不是final的话谁都有继承它的自由不需要事前通知父类. Eclipse实现不是重父类开始找而是重子类往回 ...

  3. Js获取后台集合List的值和下标的方法

    Js获取后台集合List的值和下标的方法 转载自:http://blog.csdn.net/XiaoKanZheShiJie/article/details/47280449 首先用的是struts2 ...

  4. 从值栈获取List集合

    -------------------siwuxie095 从值栈获取 List 集合 1.具体步骤 (1)在 Action 中向值栈放 List 集合 (2)在 JSP 页面中从值栈获取 List ...

  5. 反射方式,获取出集合ArrayList类的class文件对象

    /* * 定义集合类,泛型String * 要求向集合中添加Integer类型 * * 反射方式,获取出集合ArrayList类的class文件对象 * 通过class文件对象,调用add方法 * * ...

  6. Java分享笔记:使用entrySet方法获取Map集合中的元素

    /*--------------------------------- 使用entrySet方法取出Map集合中的元素: ....该方法是将Map集合中key与value的关系存入到了Set集合中,这 ...

  7. Unity3D_06_根据Transform、GameObject和Tag获取子对象集合

    导引: 因为项目中难免要多次进行获取子对象或者子对象的集合,所以写一个单独的类,用来做这些操作.然后再实际的项目中,只需要使用 transform 或者 gameobject 调用这些方法就可以快速的 ...

  8. 获取单列集合,双列集合,数组的Stream流对象以及简单操作

    获取流对象 获取单列集合,双列集合,数组的流对象 单列集合获取流对象: 1.java.util.Collection接口中加入了default方法stream()获取流对象,因此其所有实现类均可通过此 ...

  9. Selenium获取页面指定元素个数

    测试需求: 获取页面中下拉框个数,并验证是否与预期个数一致 方法1:因下拉框的tagname属性值为select,可通过获取标签为select的元素来获取下拉框个数   List<WebElem ...

随机推荐

  1. [bzoj1455]罗马游戏_左偏树_并查集

    罗马游戏 bzoj-1455 题目大意:给你n个人,2种操作,m次操作:1.将i号士兵所在的集合的最小值删除 2.合并i和j两个士兵所在的团体 注释:$1\le n\le 10^6$,$1\le m ...

  2. A*算法学习(转)

    A*启发式搜索算法详解 人工智能 1导言 1.1 算法 1.2 Dijkstra算法与最佳优先搜索 1.3 A*算法 2 启发式算法 2.1 A*对启发式函数的使用 2.2 速度还是精确度? 2.3  ...

  3. asciiflow

    http://asciiflow.com/ https://maxiang.io/# http://www.jianshu.com/p/19432b5e3c60

  4. HDU4638:Group(线段树离线处理)

    Problem Description There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and ...

  5. CF799B T-shirt buying

    题目大意 有一些衣服,它们有价格.正面的颜色和反面的颜色.现有一群顾客按顺序来买存在某颜色且价格最低的衣服(不存在则不会买),求每个顾客花了多少钱. 思路 #include <cstdio> ...

  6. Android shape自定义形状,设置渐变色

      <?xml version="1.0" encoding="utf-8"?> <!-- android:shape=["rect ...

  7. 在ubuntu中安装photoshop cs6

    对于很多专业的PS高手来说,真心难以找到顺手的且可以完美替代PS的软件,所以我们这里的解决办法就是用wine来安装. 虽然网上有很多的wine安装ps的方法,但是在使用过程往住会发生莫名其妙的崩溃,体 ...

  8. C# 操作 INI 自己工作笔记(对文本框的操作)

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  9. 我在Suse 11 Sp3上使用anaconda安装TensorFlow的过程记录

    我在Suse 11 Sp3上使用anaconda安装TensorFlow的过程记录 准备安装包: gcc48 glibc--SP4-DVD-x86_64-GM-DVD1.iso tensorflow_ ...

  10. bzoj1895

    fhqtreap 其实fhqtreap只有可持久化之后才用新建节点... reverse和splay一样. //#include<bits/stdc++.h> #include<cs ...