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. play snake on windows

    今天和人吃晚饭突然想起来 之前西佳佳老师说小学期会要求两星期撸一个小游戏 有人已经撸完一个俄罗斯方块了... 菜逼我决定从最简单的贪吃蛇玩起... 我是直接参考的这个博客 算是相当简单而且很Low的实 ...

  2. Spring for Apache Kafka @KafkaListener使用及注意事项

    官方文档:   https://docs.spring.io/spring-kafka/reference/html/ @KafkaListener The @KafkaListener annota ...

  3. ZooKeeper的原理(转)

    一.ZooKeeper的角色 领导者(Leader),负责进行投票的发起和决议,更新系统状态. 学习者(Learner),包括跟随者(Follower)和观察者(Observer),Follower用 ...

  4. war包结构

    一个war包里面必含的两个目录是meta-inf和web-inf文件夹 一个war包里面必含的两个目录是meta-inf和web-inf文件夹 一个war包里面必含的两个目录是meta-inf和web ...

  5. ZPush--基于netty4实现的苹果通知推送服务(APNs)Javaclient

    简单说下实现苹果通知推送服务(APNs)client的一些要注意的地方: 使用长连接: sanboxserver是无用的,调试时直接用"gateway.push.apple.com" ...

  6. [Cypress] Create a Single Custom Cypress Command from Multiple Commands

    Cypress provides a straightforward API that allows you to define custom commands. In this lesson, we ...

  7. poj 3468 A Simple Problem with Integers(线段树+区间更新+区间求和)

    题目链接:id=3468http://">http://poj.org/problem? id=3468 A Simple Problem with Integers Time Lim ...

  8. StringIndexOutOfBoundsException

    <span style="font-family:Microsoft YaHei;font-size:14px;">public class StringIndexBo ...

  9. B1789 Y型项链 贪心

    想明白之后就是一道大水题,就是两两把最长公共前缀求出来,然后直接取最长的,然后就直接暴力算就行了... 题干: Description 欢乐岛上众多新奇的游乐项目让小可可他们玩的非常开心.现在他们正在 ...

  10. web认证方案

    web构建在http之上,而它又是无状态协议,如何控制用户访问服务器上的受限资源呢? 最原始你想法通过http基本认证,每次发请求时都向后台传递用户名密码信息,服务器每次收到请求后都先验证用户是否合法 ...