{"id":697,"date":"2015-10-24T18:02:27","date_gmt":"2015-10-24T09:02:27","guid":{"rendered":"http:\/\/gomocool.net\/gomokulog\/?p=697"},"modified":"2015-10-24T18:02:27","modified_gmt":"2015-10-24T09:02:27","slug":"c-linq%e3%81%a8%e3%81%af%e3%81%aa%e3%82%93%e3%81%9e%e3%82%84","status":"publish","type":"post","link":"https:\/\/gomokulog.gomocool.net\/?p=697","title":{"rendered":"[C#] LINQ\u3068\u306f\u306a\u3093\u305e\u3084"},"content":{"rendered":"<h2>LINQ\u3068\u306f\u306a\u3093\u305e\u3084\u3002<\/h2>\n<p>\u79c1\u7684\u306a\u3056\u3063\u304f\u308a\u7406\u89e3\u3060\u3068\u3001<span style=\"color: #ff6600;\">LINQ\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4ee5\u5916\u306e\u30c7\u30fc\u30bf\u3082\u3001SQL\u30af\u30a8\u30ea\u3063\u307d\u3044\u611f\u3058\u3067\u64cd\u4f5c\u3067\u304d\u308b\u4ed5\u7d44\u307f<\/span>\u304b\u306a\u3002<\/p>\n<p>\u79c1\u306e\u611f\u899a\u3067\u3059\u304c\u3001LINQ\u3092\u77e5\u308b\u306b\u306f\u3001\u307e\u305aSQLServer\u3084MySQL\u306e\u3088\u3046\u306a\u95a2\u4fc2\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u3044\u308f\u308c\u308b\u3082\u306e\u3092\u3001\u666e\u901a\u306b\u89e6\u308c\u308b\u30ec\u30d9\u30eb\u306b\u306a\u3063\u3066\u304b\u3089\u306e\u65b9\u304c\u3044\u3044\u3068\u601d\u3046\u3002<br \/>\nSQL\u306e\u77e5\u8b58\uff10\u3060\u3068\u3001\u7528\u8a9e\u3068\u304b\u3001\u30e1\u30ea\u30c3\u30c8\u304c\u5206\u304b\u308a\u306b\u304f\u3044\u6c17\u304c\u3059\u308b\u3002<\/p>\n<p>\u307e\u305f\u3001\u30e9\u30e0\u30c0\u5f0f\u3082\u899a\u3048\u3066\u304a\u3044\u305f\u65b9\u304c\u826f\u3044\u3002<br \/>\n\u524d\u306b\u66f8\u3044\u305f\u306e\u3067\u3001\u53c2\u8003\u307e\u3067\u306b\u3002 <a href=\"http:\/\/gomocool.net\/gomokulog\/?p=114\">\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u3068\u30e9\u30e0\u30c0\u5f0f<\/a><\/p>\n<p>\u3042\u3068\u3001\u6b32\u3092\u8a00\u3046\u306a\u3089\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u3082\u306a\u3093\u3068\u306a\u304f\u77e5\u3063\u3068\u3044\u305f\u307b\u3046\u304c\u3044\u3044\u304b\u3082\u3002 <a href=\"http:\/\/gomocool.net\/gomokulog\/?p=141\">\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u3068\u306f\u306a\u3093\u305e\u3084<\/a><\/p>\n<p>\u3055\u3066\u3001\u4e0a\u8a18\u3092\u8e0f\u307e\u3048\u305f\u3046\u3048\u3067\u3001\u3042\u3089\u305f\u3081\u3066\u8aac\u660e\u3059\u308b\u3068\u3001LINQ\u3068\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3060\u3051\u3067\u306a\u304f\u3001XML\u3084\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5165\u3063\u305f\u914d\u5217\u3068\u304b\u3001\u3044\u308f\u3086\u308b\u300c\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u300d\u3068\u3057\u3066\u5b58\u5728\u3059\u308b\u3082\u306e\u306b\u3001SQL\u30af\u30a8\u30ea\u7684\u306a\u65b9\u6cd5\u3067\u540c\u3058\u3088\u3046\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u3092\u76ee\u7684\u3068\u3057\u3066\u5b9f\u88c5\u3055\u308c\u305f\u3002\u3089\u3057\u3044\u3002<\/p>\n<p>\u306a\u306e\u3067\u3001\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u3054\u3068\u306b\u3001\u540d\u524d\u304c\u3044\u304f\u3064\u304b\u5206\u304b\u308c\u3066\u3044\u308b\u3002<br \/>\n(LINQ to SQL, LINQ to XML, LINQ to Entity, LINQ to Object &#8230;)<br \/>\n\u8272\u3005\u5206\u304b\u308c\u3066\u3053\u305d\u3044\u308b\u304c\u3001\u300c\u540c\u3058\u3088\u3046\u306b\u30a2\u30af\u30bb\u30b9\u300d\u3053\u3068\u304c\u76ee\u7684\u306a\u306e\u3067\u3001\u3069\u308c\u304b\u899a\u3048\u308c\u3070\u4f3c\u305f\u3088\u3046\u306a\u611f\u3058\u3067\u4ed6\u3082\u4f7f\u3048\u308b\u3063\u307d\u3044\u3002<br \/>\nXML \u3068 Object\u3057\u304b\u3064\u304b\u3063\u305f\u3053\u3068\u306a\u3044\u3051\u3069\u3001\u78ba\u304b\u306b\u300c\u691c\u7d22\u300d\u3068\u3044\u3046\u70b9\u306b\u95a2\u3057\u3066\u306f\u307b\u307c\u540c\u3058\u304b\u306a\u3068\u601d\u3063\u305f\u3002<\/p>\n<h2>LINQ to Object \u3092\u3056\u3063\u304f\u308a\u77e5\u308b<\/h2>\n<p>\u3053\u3053\u304b\u3089\u306f\u3001\u3069\u3093\u306a\u74b0\u5883\u3067\u3082\u4f7f\u3048\u308b\u3057\u4f7f\u3046\u3060\u308d\u3046LINQ to Object\u306b\u3064\u3044\u3066\u3056\u3063\u304f\u308a\u8aac\u660e\u3059\u308b\u3002<br \/>\n\u3042\u304f\u307e\u3067\u3001\u300c\u3056\u3063\u304f\u308a\u300d\u306a\u306e\u3067\u300c\u5206\u304b\u3063\u3066\u306a\u3044\u300d\u611f\u306f\u3042\u308b\u3051\u3069\u3001\u307e\u3041\u3001\u3044\u3044\u3058\u3083\u306a\u3044\u3067\u3059\u304b\u30a8\u30f3\u30b8\u30f3\u306e\u69cb\u9020\u3092\u3057\u3089\u306a\u304f\u3066\u3082\u8eca\u304c\u904b\u8ee2\u3067\u304d\u308c\u3070\u3002<\/p>\n<p>\u307e\u305a\u3001LINQ\u306b\u306f\u4e8c\u901a\u308a\u306e\u66f8\u304d\u65b9\u304c\u3042\u308b\u3002<br \/>\nfrom Hoge in Moge select foo \u307f\u305f\u3044\u306a<span style=\"color: #ff00ff;\">SQL\u5f0f<\/span>\u3068\u3044\u3046\u3044\u3046\u306e\u3068<br \/>\nMoge.Select(hoge =&gt; hoge.foo) \u3068\u3044\u3046<span style=\"color: #ff00ff;\">\u30e1\u30bd\u30c3\u30c9\u5f62\u5f0f<\/span>\u304c\u3042\u308b\u3002<\/p>\n<p>\u591a\u304f\u306e\u30b5\u30a4\u30c8\u3084\u516c\u5f0f\u3067\u306fSQL\u5f0f\u3092\u524d\u63d0\u3068\u3057\u3066\u3044\u308b\u304c\u3001\u79c1\u306f\u306a\u3093\u3068\u306a\u304f\u30e1\u30bd\u30c3\u30c9\u5f62\u5f0f\u3064\u304b\u3063\u3066\u307e\u3059\u3002<br \/>\n\u306a\u306e\u3067\u3001\u3053\u3053\u3067\u51fa\u3066\u304f\u308b\u4f8b\u306f\u5168\u90e8\u30e1\u30bd\u30c3\u30c9\u5f62\u5f0f\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001\u3059\u3054\u3044\u7c21\u5358\u306a\u4f8b\u3092\u3002<\/p>\n<pre class=\"lang:c# decode:true \">\/\/  \u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u3092\u7528\u610f\r\nint[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };\r\n\r\n\/\/\u5076\u6570\u3060\u3051\u30b2\u30c3\u30c8\u3059\u308b\u30af\u30a8\u30ea\u5f0f\r\nvar numQuery = numbers.Where(num =&gt; (num % 2) == 0);\r\n\r\n\/\/foreach\u3067\u3050\u308b\u3050\u308b\u56de\u3057\u3066\u8868\u793a\r\nforeach (int num in numQuery)\r\n{\r\n  Console.WriteLine(num);\r\n}<\/pre>\n<p>\u914d\u5217\u304b\u30892\u3067\u5272\u3063\u30660\u306b\u306a\u308b\u5076\u6570\u3092\u8868\u793a\u3057\u3066\u3044\u304f\u4f8b\u3067\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u5f93\u6765\u3060\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u3044\u3066\u3044\u305f\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:c# decode:true \">\/\/\u5f93\u6765\u3060\u3063\u305f\u3089\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304f\r\nforeach (var num in numbers)\r\n{\r\n\tif ((num % 2) == 0)\r\n\t{\r\n\t\tConsole.WriteLine(num);\r\n\t}\r\n}<\/pre>\n<p>\u3053\u308c\u3060\u3051\u3060\u3068\u3001\u4fbf\u5229\u3069\u3053\u308d\u304b\u7121\u99c4\u306b\u3055\u3048\u611f\u3058\u308b\u3002\u3057\u304b\u3082<span class=\"lang:c# decode:true  crayon-inline \">Where(num =&gt; ( num % 2 ) == 0)<\/span> \u306a\u3093\u3066\u898b\u6163\u308c\u306a\u3044\u5f0f\u3082\u3067\u3066\u304d\u3066\u3001\u30e9\u30e0\u30c0\u5f0f\u3082SQL\u30af\u30a8\u30ea\u3082\u3088\u304f\u5206\u304b\u3063\u3066\u306a\u3044\u3053\u308d\u306b\u898b\u305f\u3068\u304d\u306f\u3001\u300c\u3044\u3084\u3044\u3044\u3001\u4ffa\u306f\u5f53\u5206\u5f93\u6765\u3067\u3044\u3044\u3002\u300d\u3068\u8ae6\u3081\u305f\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001LINQ\u306e\u4fbf\u5229\u3055\u306f\u3001\u30af\u30e9\u30b9\u3060\u3063\u305f\u308a\u3092\u4f7f\u3046\u6642\u306b\u9a5a\u7570\u7684\u306b\u4fbf\u5229\u306b\u306a\u308b\u3053\u3068\u304c\u5206\u304b\u3063\u305f\u3002<br \/>\n\u3053\u3053\u304b\u3089\u306f\u3001\u7121\u7406\u3057\u3066\u899a\u3048\u305a\u306b\u3001\u300c\u3078\u3047\u3001\u305d\u3093\u306a\u3093\u3067\u304d\u308b\u3060\u3002\u300d\u3067\u6d41\u3057\u8aad\u307f\u3057\u3066\u307b\u3057\u3044\u3002<\/p>\n<p>\u307e\u305a\u3001student\u3068\u3044\u3046\u30af\u30e9\u30b9\u304c\u3042\u3063\u305f\u3068\u3059\u308b\u3002<br \/>\n\u6c0f\u540d\u3068\u6027\u5225\u3068\u70b9\u6570\u30ea\u30b9\u30c8\u306a\u30af\u30e9\u30b9\u3002<\/p>\n<pre class=\"lang:c# decode:true\">class Student\r\n{\r\n\tpublic string First { get; set; }\r\n\tpublic string Last { get; set; }\r\n\tpublic byte Sex { get; set; }\r\n\r\n\tpublic List&lt;int&gt; Scores;\r\n}<\/pre>\n<p>\u305d\u3057\u3066\u3001\u9069\u5f53\u306b\u30c7\u30fc\u30bf\u3092\u5165\u308c\u308b\u3002<\/p>\n<pre class=\"lang:c# decode:true \">\/\/\u9069\u5f53\u306b\u30c7\u30fc\u30bf\u3044\u308c\u308b\r\nvar studentList = new List&lt;Student&gt;();\r\n\r\nvar taro = new Student()\r\n{\r\n\tFirst = \"Taro\",\r\n\tLast = \"Yamada\",\r\n\tSex = 0,\r\n\tScores = new List&lt;int&gt;() { 80, 75, 77 }\r\n};\r\nstudentList.Add(taro);\r\n\r\nvar hanako = new Student()\r\n{\r\n\tFirst = \"Hanako\",\r\n\tLast = \"Yamada\",\r\n\tSex = 1,\r\n\tScores = new List&lt;int&gt;() { 50, 65, 30 }\r\n};\r\nstudentList.Add(hanako);\r\n\r\nvar ichiro = new Student()\r\n{\r\n\tFirst = \"Ichiro\",\r\n\tLast = \"Suzuki\",\r\n\tSex = 0,\r\n\tScores = new List&lt;int&gt;() { 90, 99, 85 }\r\n};\r\nstudentList.Add(ichiro);<\/pre>\n<p>\u3093\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u64cd\u4f5c\u3067\u304d\u308b\u3002<\/p>\n<h3>\u540d\u5b57\u304cYamada\u3055\u3093\u3060\u3051\u53d6\u5f97<\/h3>\n<pre class=\"lang:c# decode:true\">var yamadas = studentList.Where(student =&gt; student.Last == \"Yamada\");\r\n\r\nforeach (var m in yamadas)\r\n{\r\n\tConsole.WriteLine(m.Last + \" \" + m.First);\r\n}\r\n\/\/Yamada Tro\r\n\/\/Yamada Hanako<\/pre>\n<h3>Score\u306e\u5e73\u5747\u304c80\u4ee5\u4e0a\u306e\u4eba\u3092\u53d6\u5f97<\/h3>\n<pre class=\"lang:c# decode:true\">var av80over = studentList.Where(student =&gt; student.Scores.Average() &gt; 80);\r\nforeach (var m in av80over)\r\n{\r\n\tConsole.WriteLine(m.Last + \" \" + m.First);\r\n}\r\n\/\/Suzuki Ichiro<\/pre>\n<h3>\u904e\u53bb\u306b80\u70b9\u3092\u4e00\u5ea6\u3082\u53d6\u3063\u305f\u3053\u3068\u304c\u306a\u3044\u5973\u6027\u3092\u53d6\u5f97<\/h3>\n<pre class=\"lang:c# decode:true\">var foolHanako = studentList.Where(student =&gt; student.Scores.Where(point =&gt; point &gt; 80).Count() == 0 &amp;&amp; student.Sex == 1);\r\nforeach (var m in foolHanako)\r\n{\r\n\tConsole.WriteLine(m.Last + \" \" + m.First);\r\n}\r\n\/\/Yamada Hanako<\/pre>\n<p>\u6700\u521d\u306e\u540d\u524d\u3067\u7d5e\u308a\u8fbc\u3080\u3060\u3051\u306a\u3089\u5f93\u6765\u306e\u3084\u308a\u304b\u305f\u3067\u3044\u3044\u3051\u3069\u3001\u6761\u4ef6\u304c\u8907\u6570\u306b\u306a\u3063\u305f\u308a\u3001\u30af\u30e9\u30b9\u306e\u4e2d\u306bList\u3092\u6301\u3061\u3001\u305d\u306eList\u306e\u4e2d\u8eab\u3060\u3063\u305f\u308a\u304c\u7d61\u3080\u3068\u3001foreach\u306e\u4e2d\u306bforeach\u3068\u30eb\u30fc\u30d7\u5206\u306e\u30cd\u30b9\u30c8\u306b\u306a\u308a\u304b\u306d\u306a\u3044\u304c\u3001LINQ\u3067\u3042\u308c\u3070\u3001SQL\u306e\u6761\u4ef6\u3067\u7d5e\u308b\u3088\u3046\u306a\u611f\u899a\u3067\u66f8\u3051\u3066\u3044\u308b\u3068\u601d\u3046\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3058\u3083\u306a\u3044\u306e\u306b\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u3088\u3046\u306b\u30e1\u30e2\u30ea\u5185\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u3044\u3058\u308c\u308b\u3002<br \/>\n\u3082\u3061\u308d\u3093\u4e26\u3073\u66ff\u3048\u3082\u3067\u304d\u308b\u3002(OrderBy\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308b)<br \/>\n\u300c\u904e\u53bb\u306b80\u4ee5\u4e0a\u3092\u53d6\u3063\u305f\u3053\u3068\u304c\u3042\u308b\u3001\u30e6\u30fc\u30b6\u30fc\u3092\u5e73\u5747\u70b9\u9806\u306b\u4e26\u3079\u3066\u300d\u3068\u8a00\u308f\u308c\u305f\u3089\u3001SQL\u306a\u3089\u60f3\u50cf\u304c\u3064\u304f\u304c\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u66f8\u304f\u3068\u306a\u308b\u3068\u300c\u3048\uff5e\u3063\u3068\u300d\u3063\u3066\u8003\u3048\u8fbc\u3093\u3066\u3044\u305f\u3002<\/p>\n<p>SQL\u3092\u3042\u308b\u7a0b\u5ea6\u77e5\u3063\u3066\u3044\u308b\u3068\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3084\u308b\u3088\u308a\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3068\u304d\u306bSQL\u3067\u66f8\u3044\u3066\u53d6\u5f97\u3057\u306a\u304a\u3057\u305f\u307b\u3046\u304c\u3001\u697d\u3060\u3057\u624b\u3063\u53d6\u308a\u65e9\u3044\u3068\u601d\u3063\u3066\u305f\u304c\u3001\u3053\u308c\u3092\u899a\u3048\u305f\u5f8c\u3060\u3068\u3069\u3046\u3060\u308d\u3046\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30de\u306fif\u3068for\u3068while\u304c\u3042\u308c\u3070\u4e8b\u8db3\u308a\u308b\u3068\u601d\u3063\u3066\u3044\u305f\u304c\u3001\u8907\u96d1\u306a\u30c7\u30fc\u30bf\u3092\u6271\u3046\u5834\u5408LINQ\u306f\u4f7f\u3046\u3079\u304d\u30e1\u30ea\u30c3\u30c8\u304c\u3042\u308b\u3068\u601d\u3046\u3002<br \/>\nfor\u3084foreach\u304c3\u3064\u307b\u3069\u30cd\u30b9\u30c8\u3057\u305f\u3089LINQ\u306e\u307b\u3046\u304c\u697d\u304b\u3082\uff1f<\/p>\n<h2>Where\u3060\u3051\u899a\u3048\u3068\u304f<\/h2>\n<p>\u901a\u5e38\u306eSQL\u3067\u3082\u305d\u3046\u3060\u3051\u3069\u3001\u3088\u304f\u4f7f\u3046\u306e\u306f Where \u306a\u611f\u3058\u3067\u3059\u3002<br \/>\n\u306a\u306e\u3067\u3001\u307e\u305aWhere\u3060\u3051\u899a\u3048\u3066\u304a\u3051\u3070\u3001\u6700\u4f4e\u9650\u306e\u7d5e\u8fbc\u306f\u4f7f\u3048\u308b\u6c17\u304c\u3059\u308b\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u4f55\u304b\u3057\u3089\u30c7\u30fc\u30bf\u7fa4\u3068\u306a\u308b\u3082\u306e\u3092\u3001\u30d9\u30fc\u30b9\u306b\u3001Where\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u3002<br \/>\nDictionary\u3084List\u306a\u3069\u3068\u306b\u304b\u304f<span style=\"color: #ff00ff;\">IEnumerable<\/span>\u3092\u7d99\u627f\u3057\u3066\u3044\u308c\u3070\u3001\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u3068\u3057\u3066\u4f7f\u3048\u308b\u3002<br \/>\nIEnumer..\u306a\u3093\u3060\u3063\u3066\uff1f\u3063\u3066\u601d\u3046\u4eba\u3082\u3044\u308b\u304b\u3082\u3060\u304c\u3001\u307e\u3041\u3001\u300c\u3075\u30fc\u3093\u3001\u3088\u304f\u5206\u304b\u3089\u3093\u3051\u3069IEnumerable\u3063\u3066\u3084\u3064\u3092\u4f7f\u3063\u3066\u3044\u308b\u7cfb\u3060\u3063\u305f\u3089\u4f7f\u3048\u308b\u3063\u307d\u3044\u306a\u3002\u300d\u3067\u3068\u308a\u3042\u3048\u305a\u3088\u3044\u304b\u3068\u3002<\/p>\n<p>\u3067\u306f\u3001\u5148\u307b\u3069\u306e\u4f8b\u306estudentList\u3067\u8003\u3048\u308b\u3002<\/p>\n<p>studentList\u306eWhere\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u3002(List\u3084Dictionary\u7b49\u306eIEnumerable\u7d99\u627f\u7cfb\u306a\u3089\u3070Where\u30e1\u30bd\u30c3\u30c9\u3092\u6301\u3063\u3066\u3044\u308b\u306f\u305a)<br \/>\n\u5f15\u6570\u3092\u9069\u5f53\u306b\u6c7a\u3081\u308b\u3002\u95a2\u6570\u306e\u5f15\u6570\u540d\u306a\u306e\u3067\u306a\u3093\u3067\u3082\u3088\u3044\u3002(\u4eee\u306bmoge\u3068\u3059\u308b)<br \/>\n\u3093\u3067\u3001bool\u5024\u3092\u8fd4\u3059\u6761\u4ef6\u5f0f\u3092\u5165\u308c\u308b\u3002(moge\u306e\u82d7\u5b57\u304choge\u306a\u3089\u3070\u771f)<br \/>\n<span class=\"lang:default decode:true  crayon-inline\">studentList.Where( moge =&gt; moge.Last == &#8220;hoge&#8221;)<\/span><\/p>\n<p>\u3068\u3044\u3063\u305f\u611f\u3058\u3067\u4f7f\u3046\u3002<\/p>\n<p>Where\u306e\u4e2d\u306b\u306f\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u306a\u30c7\u30ea\u30b2\u30fc\u30c8\u306eFunc&lt;T , Tresult&gt; \u304c\u4f7f\u308f\u308c\u3066\u304a\u308a\u3001Student\u306eList\u3067Where\u3060\u3068\u4e2d\u8eab\u306f bool Func&lt;Student, bool&gt;(Student arg) \u3068\u306a\u308a\u3001Student\u578b\u3092\u5f15\u6570\u306b\u6301\u3061\u3001bool\u3092\u8fd4\u3059\u30c7\u30ea\u30b2\u30fc\u30c8\u3068\u306a\u308a\u3001\u3055\u3089\u306b\u578b\u63a8\u8ad6\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u578b\u540d\u306f\u4e0d\u8981\u3067\u30e9\u30e0\u30c0\u5f0f\u3067\u66f8\u3044\u305f\u7d50\u679c\uff5e\u30fb\u30fb\u30fb\u30fb\u3002<\/p>\n<p>\u3068\u306b\u304b\u304f\u3001<span style=\"text-decoration: underline; color: #ff00ff;\">Where\u306f\u30b3\u30f3\u30c6\u30ca\u306e\u4e2d\u8eab\u3092\u5f15\u6570\u306b\u3068\u3063\u3066\u3001bool\u5024\u3092\u8fd4\u3059\u6761\u4ef6\u5f0f\u3092\u5165\u308c\u308c\u3070\u3088\u3044<\/span>\u3002<\/p>\n<p>\u6975\u7aef\u3060\u3051\u3069\u3001<span class=\"lang:c# decode:true  crayon-inline \">studentList.Where( f =&gt; true );<\/span> \u3053\u3093\u306a\u3093\u3067\u3082\u3088\u3044\u3002<\/p>\n<p>\u307e\u305f\u3001\u524d\u306e\u30e9\u30e0\u30c0\u306e\u8a18\u4e8b\u3067\u66f8\u3044\u305f\u3088\u3046\u306b\u30011\u884c\u3060\u304b\u3089\u7701\u7565\u3055\u308c\u3066\u3044\u308b\u3051\u3069\u3001\u7701\u7565\u3059\u308b\u524d\u306b\u623b\u305b\u3070\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u611f\u3058\u306b\u3082\u304b\u3051\u308b\u3002<\/p>\n<pre class=\"lang:c# decode:true\">var girls = studentList.Where( \r\n\tstudent =&gt; {\r\n\t\tbool result = false;\r\n\t\tif( student.Sex == 1)\r\n\t\t{\r\n\t\t\tresult = true;\r\n\t\t}\r\n\t\treturn result;\r\n\t}\r\n);\r\n<\/pre>\n<p>\u3053\u308c\u3067\u3001Where\u306f<span style=\"color: #333399;\">\u3068\u308a\u3042\u3048\u305a<\/span>\u4f7f\u3048\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2>\u9045\u5ef6\u5b9f\u884c<\/h2>\n<p>LINQ\u4f7f\u3046\u4e0a\u3067\u4e00\u5fdc\u77e5\u3063\u3066\u304a\u304b\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u4e8b\u304c\u3042\u308b\u3002<\/p>\n<p><strong><span style=\"color: #ff00ff;\">LINQ\u306f\u9045\u5ef6\u5b9f\u884c\u3068\u306a\u308b<\/span>\u3002<\/strong><\/p>\n<p>LINQ\u306e\u30af\u30a8\u30ea\u306f\u3001\u7279\u5b9a\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u304b\u3001foreach\u3067\u547c\u3070\u308c\u306a\u3044\u3068\u3001\u307f\u3093\u306a\u304c\u60f3\u50cf\u3059\u308b\u666e\u901a\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u306f\u306a\u3089\u306a\u3044\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u3055\u304d\u307b\u3069\u306eYamada\u3060\u3051\u3092\u53d6\u308a\u51fa\u3059\u95a2\u6570\u3092\u307f\u308b\u3002<\/p>\n<pre class=\"lang:c# decode:true\">var testYamda = studentList.Where(student =&gt; student.Last == \"Yamada\");<\/pre>\n<p>\u578b\u63a8\u8ad6 var \u306f\u3001List&lt;Student&gt;\u3092\u53d6\u5f97\u3057\u3066\u3044\u308b\u308f\u3051\u3067\u306a\u304f\u3001IEnumerable&lt;Student&gt;\u3092\u53d6\u5f97\u3059\u308b\u3002<\/p>\n<pre class=\"lang:c# decode:true\">\/\/\u3053\u3093\u306a\u30a4\u30e1\u30fc\u30b8\u3092\u60f3\u50cf\u3059\u308b\u304c\u3053\u308c\u306f\u30a8\u30e9\u30fc\r\nList&lt;Student&gt; result = studentList.Where(student =&gt; student.Last == \"Yamada\");\r\n\r\n\/\/\u5b9f\u969b\u306fIEnumerable\u304c\u8fd4\u3063\u3066\u3044\u308b\r\nIEnumerable&lt;Student&gt; result = studentList.Where(student =&gt; student.Last == \"Yamada\");<\/pre>\n<p>\u4f55\u304c\u9055\u3046\u304b\u3068\u3044\u3046\u3068\u3001<span style=\"text-decoration: underline;\">IEnumerable\u306f\u7d50\u679c\u3092\u6c42\u3081\u308b\u305f\u3081\u306e\u8a08\u7b97\u5f0f\u3060\u3051\u304c\u5165\u3063\u3066\u304a\u308a<\/span>\u3001\u8a08\u7b97\u304c\u5b9f\u884c\u3055\u308c\u306a\u3044\u3068\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u306a\u3089\u306a\u3044\u3002<\/p>\n<p>\u4f55\u3092\u8a00\u3063\u3066\u3044\u308b\u304b\u610f\u5473\u304c\u308f\u304b\u3089\u306a\u3044\u304b\u3082\u3057\u308c\u3044\u306a\u3044\u3057\u3001\u4ffa\u3082\u4f55\u3092\u8a00\u3063\u3066\u3044\u308b\u304b\u5206\u304b\u3089\u306a\u3044\u3093\u3060\u304c\u3001\u307e\u3041\u3001\u305d\u3046\u3044\u3046\u7269\u3060\u3068\u3053\u3053\u306f\u7406\u89e3\u3057\u3088\u3046\u3058\u3083\u306a\u3044\u304b\u3002<\/p>\n<p>\u306a\u305c\u3053\u306e\u3088\u3046\u306a\u3053\u3068\u3092\u3059\u308b\u306e\u304b\u3001<br \/>\n\u7406\u7531\u306f\u8272\u3005\u3042\u308b\u307f\u305f\u3044\u3060\u3051\u3069\u3001\u4e3b\u306b\u7701\u30e1\u30e2\u30ea\u3001\u7701\u30a2\u30af\u30bb\u30b9\u3001\u7701\u8a08\u7b97\u3068\u304b\uff1f<br \/>\n\u306f\u3084\u308a\u306eMVC\u3067\u8a00\u3046\u306a\u3089\u3001\u5b9f\u969b\u306b\u30e6\u30fc\u30b6\u30fc\u306b\u8868\u793a\u3055\u305b\u308bView\u306b\u306a\u308b\u307e\u3067\u3001\u4f59\u8a08\u306a\u30e1\u30e2\u30ea\u6d88\u8cbb\u3092\u306a\u304f\u3059\u3053\u3068\u3067\u3001\u8efd\u304f\u306a\u308b\u3068\u304b\uff1f<br \/>\n\u5927\u91cf\u306e\u30e1\u30e2\u30ea\u3092\u4f7f\u3048\u308b\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u306e\u30a2\u30d7\u30ea\u306a\u3089\u3068\u3082\u304b\u304f\u3001\u307f\u3093\u306a\u3067\u5171\u7528\u3059\u308b\u30b5\u30fc\u30d0\u30fc\u306e\u30e1\u30e2\u30ea\u3092\u7bc0\u7d04\u3059\u308b\u3053\u3068\u306f\u78ba\u304b\u306b\u5927\u4e8b\u304b\u3082\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u5b9f\u969b\u306b\u8a08\u7b97\u3055\u308c\u308b\u30c8\u30ea\u30ac\u30fc\u306f\u3001ToArray()\u3068ToList()\u3068ToDictionary()\u3068First()\u306a\u3069\u306a\u3069\u3002<br \/>\n\u5148\u307b\u3069\u306e\u7d5e\u308a\u8fbc\u3093\u3060testYamada\u3092\u5b9f\u969b\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304f\u3002<\/p>\n<pre class=\"lang:c# decode:true\">Student[] realarr = testYamda.ToArray();\r\n\r\nList&lt;Student&gt; reallist = testYamda.ToList();\r\n\r\nStudent firstYamada = testYamda.First();\r\n\r\n\/\/foreach\u3067\u53d6\u308a\u51fa\u3057\u305f\u5834\u5408\r\nforeach (Student s in testYamda)\r\n{\r\n    Console.WriteLine(s.Last + \" \" + s.First);\r\n}<\/pre>\n<p>\u3064\u307e\u308a\u3001\u305b\u3063\u304b\u304f\u306e\u9045\u5ef6\u5b9f\u884c\u3082\u3053\u306e\u30c8\u30ea\u30ac\u30fc\u3067\u3001\u5373\u6642\u5b9f\u884c\u3055\u305b\u3059\u304e\u308b\u3068\u610f\u5473\u304c\u306a\u3044\u3002<br \/>\n\u53ef\u80fd\u306a\u9650\u308aIEnumerable\u306e\u307e\u307e\u6301\u3061\u56de\u3059\u306e\u304c\u3044\u3044\u3088\u3046\u3060\u3002<\/p>\n<p>\u3056\u3063\u304f\u308a\u3060\u3051\u3069\u4ee5\u4e0a\u3002<\/p>\n<p>Select\u3068\u304b\u4ed6\u306b\u3082\u3042\u308b\u3093\u3060\u3051\u3069\u3001\u3068\u308a\u3042\u3048\u305aWhere\u3067\u904a\u3079\u3070\u3001\u3042\u3068\u306fSQL\u7684\u306a\u611f\u899a\u3067\u899a\u3048\u308c\u308b\u6c17\u304c\u3059\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LINQ\u3068\u306f\u306a\u3093\u305e\u3084\u3002 \u79c1\u7684\u306a\u3056\u3063\u304f\u308a\u7406\u89e3\u3060\u3068\u3001LINQ\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4ee5\u5916\u306e\u30c7\u30fc\u30bf\u3082\u3001SQL\u30af\u30a8\u30ea\u3063\u307d\u3044\u611f\u3058\u3067\u64cd\u4f5c\u3067\u304d\u308b\u4ed5\u7d44\u307f\u304b\u306a\u3002 \u79c1\u306e\u611f\u899a\u3067\u3059\u304c\u3001LINQ\u3092\u77e5\u308b\u306b\u306f\u3001\u307e\u305aSQLServer\u3084MySQL\u306e\u3088\u3046\u306a\u95a2\u4fc2\u30c7\u30fc&hellip;  <a href=\"https:\/\/gomokulog.gomocool.net\/?p=697\" class=\"more-link\">more <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[58],"class_list":["post-697","post","type-post","status-publish","format-standard","hentry","category-csharp","tag-linq"],"_links":{"self":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/697","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=697"}],"version-history":[{"count":8,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/697\/revisions"}],"predecessor-version":[{"id":706,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/697\/revisions\/706"}],"wp:attachment":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}