{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/csharp-ienumerable/",
  "atlas": "https://www.pystone.net/?node=csharp-ienumerable#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/csharp-ienumerable.md",
  "context": "https://www.pystone.net/notes/csharp-ienumerable.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:csharp-ienumerable",
  "slug": "csharp-ienumerable",
  "title": "IEnumerable",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "IEnumerable",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "0700a2dc6ce194eb85ea857bee2ca822d90e2c298ecc7e5cda9d08012d8bd3aa",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "IEnumerable",
      "anchor": "ienumerable",
      "citation": "https://www.pystone.net/notes/csharp-ienumerable/#ienumerable"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:programming-languages-and-runtimes",
      "title": "编程语言与运行时",
      "url": "https://www.pystone.net/notes/programming-languages-and-runtimes/",
      "atlas": "https://www.pystone.net/?node=programming-languages-and-runtimes#knowledge-atlas",
      "label": "编程语言与运行时",
      "origin": "explicit",
      "humanReviewed": true,
      "context": ".NET与CSharp中的“IEnumerable”导航项",
      "citation": "https://www.pystone.net/notes/programming-languages-and-runtimes/#net%E4%B8%8Ecsharp"
    }
  ],
  "contentMarkdown": "# IEnumerable\n\n> 创建时间：2020/5/18 13:20\n\nenumerable 可数的，可枚举的\n在使用Linq查询数据时经常以IEnumerable来作为数据查询返回对象\n使用foreach进行遍历时需要该对象实现IEnumerable接口\n定义了一个GetEnumerator()方法\n依靠MoveNext和Current来达到Foreach的遍历\n\n定义一个集合FruitShop类，它是一个关于Fruit对象的集合\n流程:\n第一次遇到foreach里的fruitShop对象时就会去执行FruitShop中的GetEnumerator方法\n接着每次执行in关键字就会去执行MoveNext方法\n每次取数据则是调用Current属性\n\n```csharp\nclass MyClass&lt;T, U&gt;\n    where T : class\n    where U : struct\n{ }\n\n```\n\nIEnumerable还有4个扩展方法\n\n  * Cast()\n\n  * OfType()\n非泛型集合比如ArrayList，它只实现了IEnumerable接口而没有实现IEnumerable接口，因此无法使用标准查询运算。\n但是标准查询运算如此的方便，.NET肯定不会允许这样的不完美发生，于是为IEnumerable提供了2个扩展方法进行强制转换。\nOfType比Cast更加强大，它除了进行强制转换外还可以实现类型的过滤，遇到无法强制转换的数据将不会转换\n进行转换时OfType是首选\n\n```csharp\nclass MyClass&lt;T, U&gt;\n    where T : class\n    where U : struct\n{ }\n\n```\n"
}
