{"id":343116,"date":"2022-12-25T21:00:18","date_gmt":"2022-12-25T21:00:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343116"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2022-12-25T21:00:18","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343116","title":{"rendered":"<span>\u041c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0432 C#<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041a\u0430\u043a \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 Microsoft<\/h2>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f &#8212; \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0432 \u0440\u0430\u0437\u044b. \u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440 Microsoft, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f LINQ.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0435\u0441\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0438\u0437 \u0441\u0442\u0440\u043e\u043a. \u0423 \u043d\u0430\u0441 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043b\u0430\u0442\u0438\u043d\u0441\u043a\u0443\u044e \u0431\u0443\u043a\u0432\u0443 &#171;A&#187;. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0448\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443<\/p>\n<pre><code class=\"cs\">var array = new[] {   \"Array\", \"Adapter\", \"Class\", \"Interface\"   }; \/\/ \u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438  \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 Where \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 Enumerable var startsWithA = Enumerable.Where(array, s => s.StartsWith('A'));  \/\/ \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 foreach (var s in startsWithA) {     Console.WriteLine(s); }<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0431\u044b\u0447\u043d\u043e. \u041d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0435\u0433\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>Where<\/code> \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043d\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043d\u044b\u0439. \u0418 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0440\u0435\u0448\u0430\u044e\u0442 \u043a\u0430\u043a \u0440\u0430\u0437 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0431\u0435\u0437 \u043f\u043e\u0442\u0435\u0440\u0438 \u0441\u043c\u044b\u0441\u043b\u0430<\/p>\n<pre><code class=\"cs\">var array = new[] {   \"Array\", \"Adapter\", \"Class\", \"Interface\"   }; \/\/ \u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438  \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f Where var startsWithA = array.Where(s => s.StartsWith('A'));  \/\/ \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 foreach (var s in startsWithA) {     Console.WriteLine(s); }<\/code><\/pre>\n<p>\u0421\u0442\u0440\u043e\u0447\u043a\u0430 \u0441 \u043e\u0442\u0431\u043e\u0440\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043b\u0430 \u043e\u043f\u0440\u044f\u0442\u043d\u0435\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>Where<\/code><\/p>\n<pre><code class=\"cs\">public static IEnumerable&lt;TSource> Where&lt;TSource>(this IEnumerable&lt;TSource> source,                                                   Func&lt;TSource, bool> predicate)<\/code><\/pre>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e this, \u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u043f\u0435\u0440\u0435\u0434 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u0432\u0435\u0440\u0448\u0438\u0442 \u0432\u0441\u044e \u043c\u0430\u0433\u0438\u044e. \u0418 \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0442\u0438\u043f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u0442\u043e \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 <code>IEnumerable&lt;T><\/code><\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0447\u043b\u0435\u043d\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0442\u043e\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043b\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430<\/p>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430:<\/strong> \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 CollectionWriter, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434 WriteToConsole, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0432\u0441\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e<\/p>\n<pre><code class=\"cs\">using System.Collections;  public static class CollectionWriter {     public static void WriteToConsole(IEnumerable collection)     {         foreach (var member in collection)         {             Console.WriteLine(member);         }     } }<\/code><\/pre>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a<\/p>\n<pre><code class=\"cs\">var array = new[] { \"Member1\", \"Member2\", \"Member3\" };  CollectionWriter.WriteToConsole(array);<\/code><\/pre>\n<p>\u041f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e this \u043f\u0435\u0440\u0435\u0434 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u0441\u043e\u0437\u0434\u0430\u0432 \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u043f\u043e\u043c\u0435\u0442\u043a\u0443, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f &#171;\u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0449\u0438\u043c&#187; (\u043f\u043e\u0437\u0436\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a\u0443\u044e \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u0435\u0442\u043a\u0443 \u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u043e\u0441\u043b\u0435 \u043d\u0430\u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043b\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438). \u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434<\/p>\n<pre><code class=\"cs\">public static void WriteToConsole(this IEnumerable collection)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0443\u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/p>\n<pre><code class=\"cs\">var array = new[] { \"Member1\", \"Member2\", \"Member3\" };  array.WriteToConsole();<\/code><\/pre>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0441\u043b\u043e\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0443 3 \u043d\u0430 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a.<\/p>\n<pre><code class=\"cs\">array.WriteToConsole() = \u043c\u0430\u0441\u0441\u0438\u0432.\u0412\u044b\u0432\u0435\u0441\u0442\u0438\u0412\u041a\u043e\u043d\u0441\u043e\u043b\u044c()<\/code><\/pre>\n<p>\u041d\u0443\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u044b\u043c \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430. \u0415\u0441\u043b\u0438 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a Microsoft \u0434\u043e\u0431\u0430\u0432\u0438\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043b\u0430\u0441\u0441 List&lt;T> \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 WriteToConsole, \u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 <strong>\u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/strong>, \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u0441\u0442\u0438 \u0441\u0435\u0431\u044f \u043a\u0430\u043a-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443.<\/p>\n<h2>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 &#171;\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c&#187;<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u0432\u043e \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438. \u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0440\u0435\u0442\u044c\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0432\u043e \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442 <code>array.WriteToConsole()<\/code>, \u043e\u043d \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0438 \u0435\u0433\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f\u0445. \u0415\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439, \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u043f\u043e\u0438\u0441\u043a \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0441\u0435\u0445 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043d \u043d\u0430\u0448\u0435\u043b \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441 \u043f\u043e\u043c\u0435\u0442\u043a\u043e\u0439 this \u0443 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043e\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 IL \u043a\u043e\u0434 \u0434\u043b\u044f \u043d\u0435\u0433\u043e, \u043f\u043e\u043c\u0435\u0447\u0430\u044f \u0435\u0433\u043e \u0438 \u043a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d, \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c <code>ExtensionAttribute<\/code>. \u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 IL \u043a\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">.class public abstract sealed auto ansi beforefieldinit   CollectionWriter     extends [System.Runtime]System.Object {   .custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor()     = (01 00 00 00 )    .method public hidebysig static void     WriteToConsole(       class [System.Runtime]System.Collections.IEnumerable collection     ) cil managed   {     .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor([in] unsigned int8)       = (01 00 01 00 00 ) \/\/ .....       \/\/ unsigned int8(1) \/\/ 0x01     .custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor()       = (01 00 00 00 )     .maxstack 1     .locals init (       [0] class [System.Runtime]System.Collections.IEnumerator V_0,       [1] object member,       [2] class [System.Runtime]System.IDisposable V_2     )      \/\/ [10 5 - 10 6]     IL_0000: nop      \/\/ [11 9 - 11 16]     IL_0001: nop      \/\/ [11 32 - 11 42]     IL_0002: ldarg.0      \/\/ collection     IL_0003: callvirt     instance class [System.Runtime]System.Collections.IEnumerator [System.Runtime]System.Collections.IEnumerable::GetEnumerator()     IL_0008: stloc.0      \/\/ V_0     .try     {        IL_0009: br.s         IL_001b       \/\/ start of loop, entry point: IL_001b          \/\/ [11 18 - 11 28]         IL_000b: ldloc.0      \/\/ V_0         IL_000c: callvirt     instance object [System.Runtime]System.Collections.IEnumerator::get_Current()         IL_0011: stloc.1      \/\/ member          \/\/ [12 9 - 12 10]         IL_0012: nop          \/\/ [13 13 - 13 39]         IL_0013: ldloc.1      \/\/ member         IL_0014: call         void [System.Console]System.Console::WriteLine(object)         IL_0019: nop          \/\/ [14 9 - 14 10]         IL_001a: nop          \/\/ [11 29 - 11 31]         IL_001b: ldloc.0      \/\/ V_0         IL_001c: callvirt     instance bool [System.Runtime]System.Collections.IEnumerator::MoveNext()         IL_0021: brtrue.s     IL_000b       \/\/ end of loop       IL_0023: leave.s      IL_0037     } \/\/ end of .try     finally     {        IL_0025: ldloc.0      \/\/ V_0       IL_0026: isinst       [System.Runtime]System.IDisposable       IL_002b: stloc.2      \/\/ V_2       IL_002c: ldloc.2      \/\/ V_2       IL_002d: brfalse.s    IL_0036       IL_002f: ldloc.2      \/\/ V_2       IL_0030: callvirt     instance void [System.Runtime]System.IDisposable::Dispose()       IL_0035: nop        IL_0036: endfinally     } \/\/ end of finally      \/\/ [15 5 - 15 6]     IL_0037: ret    } \/\/ end of method CollectionWriter::WriteToConsole } \/\/ end of class CollectionWriter<\/code><\/pre>\n<p>\u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u0432\u0441\u0435\u0433\u043e \u044f \u0432\u044b\u0434\u0435\u043b\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u0447\u0435\u043a \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0412\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043f\u043e\u0438\u0441\u043a \u044d\u0442\u0438\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432<\/p>\n<p><strong>\u041f\u043e\u043c\u0435\u0442\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0430<\/strong><\/p>\n<pre><code class=\"cs\">.class public abstract sealed auto ansi beforefieldinit   CollectionWriter     extends [System.Runtime]System.Object {   .custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor()     = (01 00 00 00 ) \/\/ \u0410\u0422\u0420\u0418\u0411\u0423\u0422<\/code><\/pre>\n<p><strong>\u041f\u043e\u043c\u0435\u0442\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u0430<\/strong><\/p>\n<pre><code class=\"cs\">.method public hidebysig static void     WriteToConsole(       class [System.Runtime]System.Collections.IEnumerable collection     ) cil managed   {     .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor([in] unsigned int8)       = (01 00 01 00 00 ) \/\/ .....       \/\/ unsigned int8(1) \/\/ 0x01     .custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor()       = (01 00 00 00 ) \/\/ \u0410\u0422\u0420\u0418\u0411\u0423\u0422<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043d\u0430\u0439\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 <strong>\u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043d\u044b\u0439<\/strong> \u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u043a \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430<\/p>\n<pre><code class=\"cs\">\/\/ [5 1 - 5 24] IL_001f: ldloc.0      \/\/ 'array' IL_0020: call         void CollectionWriter::WriteToConsole(class [System.Runtime]System.Collections.IEnumerable) IL_0025: nop IL_0026: ret<\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f &#8212; \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0412\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u041e\u043d\u0438 \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043a \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 \u0438\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 (\u043a\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u043b\u0430\u043b\u0430 Microsoft \u0432 LINQ \u0438\u043b\u0438 \u043c\u044b \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c IEnumerable). <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/707590\/\"> https:\/\/habr.com\/ru\/post\/707590\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041a\u0430\u043a \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 Microsoft<\/h2>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f &#8212; \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0432 \u0440\u0430\u0437\u044b. \u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440 Microsoft, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f LINQ.<\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0435\u0441\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0438\u0437 \u0441\u0442\u0440\u043e\u043a. \u0423 \u043d\u0430\u0441 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043b\u0430\u0442\u0438\u043d\u0441\u043a\u0443\u044e \u0431\u0443\u043a\u0432\u0443 &#171;A&#187;. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0448\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443<\/p>\n<pre><code class=\"cs\">var array = new[] {   \"Array\", \"Adapter\", \"Class\", \"Interface\"   }; \/\/ \u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438  \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 Where \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 Enumerable var startsWithA = Enumerable.Where(array, s => s.StartsWith('A'));  \/\/ \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 foreach (var s in startsWithA) {     Console.WriteLine(s); }<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0431\u044b\u0447\u043d\u043e. \u041d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0435\u0433\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>Where<\/code> \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043d\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043d\u044b\u0439. \u0418 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0440\u0435\u0448\u0430\u044e\u0442 \u043a\u0430\u043a \u0440\u0430\u0437 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0431\u0435\u0437 \u043f\u043e\u0442\u0435\u0440\u0438 \u0441\u043c\u044b\u0441\u043b\u0430<\/p>\n<pre><code class=\"cs\">var array = new[] {   \"Array\", \"Adapter\", \"Class\", \"Interface\"   }; \/\/ \u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438  \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f Where var startsWithA = array.Where(s => s.StartsWith('A'));  \/\/ \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 foreach (var s in startsWithA) {     Console.WriteLine(s); }<\/code><\/pre>\n<p>\u0421\u0442\u0440\u043e\u0447\u043a\u0430 \u0441 \u043e\u0442\u0431\u043e\u0440\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043b\u0430 \u043e\u043f\u0440\u044f\u0442\u043d\u0435\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 <code>Where<\/code><\/p>\n<pre><code class=\"cs\">public static IEnumerable&lt;TSource> Where&lt;TSource>(this IEnumerable&lt;TSource> source,                                                   Func&lt;TSource, bool> predicate)<\/code><\/pre>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e this, \u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u043f\u0435\u0440\u0435\u0434 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u0432\u0435\u0440\u0448\u0438\u0442 \u0432\u0441\u044e \u043c\u0430\u0433\u0438\u044e. \u0418 \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0442\u0438\u043f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u0442\u043e \u0441\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 <code>IEnumerable&lt;T><\/code><\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0447\u043b\u0435\u043d\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0442\u043e\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043b\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430<\/p>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430:<\/strong> \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 CollectionWriter, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434 WriteToConsole, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0432\u0441\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e<\/p>\n<pre><code class=\"cs\">using System.Collections;  public static class CollectionWriter {     public static void WriteToConsole(IEnumerable collection)     {         foreach (var member in collection)         {             Console.WriteLine(member);         }     } }<\/code><\/pre>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a<\/p>\n<pre><code class=\"cs\">var array = new[] { \"Member1\", \"Member2\", \"Member3\" };  CollectionWriter.WriteToConsole(array);<\/code><\/pre>\n<p>\u041f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e this \u043f\u0435\u0440\u0435\u0434 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c, \u0441\u043e\u0437\u0434\u0430\u0432 \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u043f\u043e\u043c\u0435\u0442\u043a\u0443, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f &#171;\u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0449\u0438\u043c&#187; (\u043f\u043e\u0437\u0436\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a\u0443\u044e \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u0435\u0442\u043a\u0443 \u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u043e\u0441\u043b\u0435 \u043d\u0430\u0441 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043b\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438). \u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434<\/p>\n<pre><code class=\"cs\">public static void WriteToConsole(this IEnumerable collection)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0443\u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/p>\n<pre><code class=\"cs\">var array = new[] { \"Member1\", \"Member2\", \"Member3\" };  array.WriteToConsole();<\/code><\/pre>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0441\u043b\u043e\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0443 3 \u043d\u0430 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a.<\/p>\n<pre><code class=\"cs\">array.WriteToConsole() = \u043c\u0430\u0441\u0441\u0438\u0432.\u0412\u044b\u0432\u0435\u0441\u0442\u0438\u0412\u041a\u043e\u043d\u0441\u043e\u043b\u044c()<\/code><\/pre>\n<p>\u041d\u0443\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u044b\u043c \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430. \u0415\u0441\u043b\u0438 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a Microsoft \u0434\u043e\u0431\u0430\u0432\u0438\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043b\u0430\u0441\u0441 List&lt;T> \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 WriteToConsole, \u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 <strong>\u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/strong>, \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u0441\u0442\u0438 \u0441\u0435\u0431\u044f \u043a\u0430\u043a-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e-\u0434\u0440\u0443\u0433\u043e\u043c\u0443.<\/p>\n<h2>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 &#171;\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c&#187;<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u0432\u043e \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438. \u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0440\u0435\u0442\u044c\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0432\u043e \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442 <code>array.WriteToConsole()<\/code>, \u043e\u043d \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0438 \u0435\u0433\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f\u0445. \u0415\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439, \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u043f\u043e\u0438\u0441\u043a \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u0441\u0435\u0445 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0430\u0445. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043d \u043d\u0430\u0448\u0435\u043b \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441 \u043f\u043e\u043c\u0435\u0442\u043a\u043e\u0439 this \u0443 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043e\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 IL \u043a\u043e\u0434 \u0434\u043b\u044f \u043d\u0435\u0433\u043e, \u043f\u043e\u043c\u0435\u0447\u0430\u044f \u0435\u0433\u043e \u0438 \u043a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d, \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c <code>ExtensionAttribute<\/code>. \u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 IL \u043a\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">.class public abstract sealed auto ansi beforefieldinit   CollectionWriter     extends [System.Runtime]System.Object {   .custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor()     = (01 00 00 00 )    .method public hidebysig static void     WriteToConsole(       class [System.Runtime]System.Collections.IEnumerable collection     ) cil managed   {     .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor([in] unsigned int8)       = (01 00 01 00 00 ) \/\/ .....       \/\/ unsigned int8(1) \/\/ 0x01     .custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor()       = (01 00 00 00 )     .maxstack 1     .locals init (       [0] class [System.Runtime]System.Collections.IEnumerator V_0,       [1] object member,       [2] class [System.Runtime]System.IDisposable V_2     )      \/\/ [10 5 - 10 6]     IL_0000: nop      \/\/ [11 9 - 11 16]     IL_0001: nop      \/\/ [11 32 - 11 42]     IL_0002: ldarg.0      \/\/ collection     IL_0003: callvirt     instance class [System.Runtime]System.Collections.IEnumerator [System.Runtime]System.Collections.IEnumerable::GetEnumerator()     IL_0008: stloc.0      \/\/ V_0     .try     {        IL_0009: br.s         IL_001b       \/\/ start of loop, entry point: IL_001b          \/\/ [11 18 - 11 28]         IL_000b: ldloc.0      \/\/ V_0         IL_000c: callvirt     instance object [System.Runtime]System.Collections.IEnumerator::get_Current()         IL_0011: stloc.1      \/\/ member          \/\/ [12 9 - 12 10]         IL_0012: nop          \/\/ [13 13 - 13 39]         IL_0013: ldloc.1      \/\/ member         IL_0014: call         void [System.Console]System.Console::WriteLine(object)         IL_0019: nop          \/\/ [14 9 - 14 10]         IL_001a: nop          \/\/ [11 29 - 11 31]         IL_001b: ldloc.0      \/\/ V_0         IL_001c: callvirt     instance bool [System.Runtime]System.Collections.IEnumerator::MoveNext()         IL_0021: brtrue.s     IL_000b       \/\/ end of loop       IL_0023: leave.s      IL_0037     } \/\/ end of .try     finally     {        IL_0025: ldloc.0      \/\/ V_0       IL_0026: isinst       [System.Runtime]System.IDisposable       IL_002b: stloc.2      \/\/ V_2       IL_002c: ldloc.2      \/\/ V_2       IL_002d: brfalse.s    IL_0036       IL_002f: ldloc.2      \/\/ V_2       IL_0030: callvirt     instance void [System.Runtime]System.IDisposable::Dispose()       IL_0035: nop        IL_0036: endfinally     } \/\/ end of finally      \/\/ [15 5 - 15 6]     IL_0037: ret    } \/\/ end of method CollectionWriter::WriteToConsole } \/\/ end of class CollectionWriter<\/code><\/pre>\n<p>\u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u0432\u0441\u0435\u0433\u043e \u044f \u0432\u044b\u0434\u0435\u043b\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u0447\u0435\u043a \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0412\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043f\u043e\u0438\u0441\u043a \u044d\u0442\u0438\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432<\/p>\n<p><strong>\u041f\u043e\u043c\u0435\u0442\u043a\u0430 \u043a\u043b\u0430\u0441\u0441\u0430<\/strong><\/p>\n<pre><code class=\"cs\">.class public abstract sealed auto ansi beforefieldinit   CollectionWriter     extends [System.Runtime]System.Object {   .custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor()     = (01 00 00 00 ) \/\/ \u0410\u0422\u0420\u0418\u0411\u0423\u0422<\/code><\/pre>\n<p><strong>\u041f\u043e\u043c\u0435\u0442\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u0430<\/strong><\/p>\n<pre><code class=\"cs\">.method public hidebysig static void     WriteToConsole(       class [System.Runtime]System.Collections.IEnumerable collection     ) cil managed   {     .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor([in] unsigned int8)       = (01 00 01 00 00 ) \/\/ .....       \/\/ unsigned int8(1) \/\/ 0x01     .custom instance void [System.Runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor()       = (01 00 00 00 ) \/\/ \u0410\u0422\u0420\u0418\u0411\u0423\u0422<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043d\u0430\u0439\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 <strong>\u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043d\u044b\u0439<\/strong> \u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u043a \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430<\/p>\n<pre><code class=\"cs\">\/\/ [5 1 - 5 24] IL_001f: ldloc.0      \/\/ 'array' IL_0020: call         void CollectionWriter::WriteToConsole(class [System.Runtime]System.Collections.IEnumerable) IL_0025: nop IL_0026: ret<\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f &#8212; \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0412\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u041e\u043d\u0438 \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u043a \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 \u0438\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 (\u043a\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u043b\u0430\u043b\u0430 Microsoft \u0432 LINQ \u0438\u043b\u0438 \u043c\u044b \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c IEnumerable). <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/707590\/\"> https:\/\/habr.com\/ru\/post\/707590\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-343116","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=343116"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343116\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}