{"id":310848,"date":"2020-10-01T21:00:41","date_gmt":"2020-10-01T21:00:41","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=310848"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=310848","title":{"rendered":"\u041d\u0435 \u0437\u0430\u0431\u043b\u0443\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0442\u0440\u0451\u0445 if&#8217;\u0430\u0445. \u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u0432\u0435\u0442\u0432\u044f\u0449\u0438\u0445\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u0439"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/516286\/\">\u041d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439 \u043f\u0440\u0438\u0435\u043c\u043e\u0432 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/refactoring.guru\/refactoring\/techniques\/simplifying-conditional-expressions\" rel=\"nofollow\">\u0442\u0443\u0442<\/a>). \u0412 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044f \u0438\u043d\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e <i>\u0437\u0430\u043c\u0435\u043d\u044b \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c<\/i> \u0438 <i>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432<\/i>. \u041e\u0431\u044b\u0447\u043d\u043e \u043e\u043d\u0430 \u0434\u0430\u0435\u0442 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0432\u0435\u0442\u043e\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043d\u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438. \u041a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 C#, \u043d\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 if\/else.<\/p>\n<p>  <a href=\"https:\/\/habr.com\/ru\/post\/516286\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ct\/22\/l9\/ct22l9tcejckodkrg0eaxyd5uv4.png\" alt=\"image\"><\/a><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u0414\u0430\u043d\u043e<\/h3>\n<p>  \u0415\u0441\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <i><b>IUnit<\/b><\/i>.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">IUnit<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public interface IUnit {     string Description { get; } } <\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<p>  \u0418 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <i><b>Piece<\/b><\/i> \u0438 <i><b>Cluster<\/b><\/i>.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">Piece<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public class Piece : IUnit {     public string Description { get; }      public Piece(string description) =&gt;         Description = description;      public override bool Equals(object obj) =&gt;         Equals(obj as Piece);      public bool Equals(Piece piece) =&gt;         piece != null &amp;&amp;         piece.Description.Equals(Description);      public override int GetHashCode()     {         unchecked         {             var hash = 17;             foreach (var c in Description)                 hash = 23 * hash + c.GetHashCode();              return hash;         }     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">Cluster<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public class Cluster : IUnit {     private readonly IReadOnlyList&lt;Piece&gt; pieces;      public IEnumerable&lt;Piece&gt; Pieces =&gt; pieces;      public string Description { get; }      public Cluster(IEnumerable&lt;Piece&gt; pieces)     {         if (!pieces.Any())             throw new ArgumentException();          if (pieces.Select(unit =&gt; unit.Description).Distinct().Count() &gt; 1)             throw new ArgumentException();          this.pieces = pieces.ToArray();         Description = this.pieces[0].Description;     }      public Cluster(IEnumerable&lt;Cluster&gt; clusters)         : this(clusters.SelectMany(cluster =&gt; cluster.Pieces))     {     }      public override bool Equals(object obj) =&gt;         Equals(obj as Cluster);      public bool Equals(Cluster cluster) =&gt;         cluster != null &amp;&amp;         cluster.Description.Equals(Description) &amp;&amp;         cluster.pieces.Count == pieces.Count;      public override int GetHashCode()     {         unchecked         {             var hash = 17;             foreach (var c in Description)                 hash = 23 * hash + c.GetHashCode();             hash = 23 * hash + pieces.Count.GetHashCode();              return hash;         }     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 <i><b>MergeClusters<\/b><\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 <i><b>IUnit<\/b><\/i> \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0445 <i><b>Cluster<\/b><\/i> \u0432 \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u0430\u043c\u0438.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">MergeClusters<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public class MergeClusters {     private readonly List&lt;Cluster&gt; buffer = new List&lt;Cluster&gt;();     private List&lt;IUnit&gt; merged;     private readonly IReadOnlyList&lt;IUnit&gt; units;      public IEnumerable&lt;IUnit&gt; Result     {         get         {             if (merged != null)                 return merged;              merged = new List&lt;IUnit&gt;();             Merge();              return merged;         }     }      public MergeClusters(IEnumerable&lt;IUnit&gt; units)     {         this.units = units.ToArray();     }      private void Merge()     {         Seed();          for (var i = 1; i &lt; units.Count; i++)             MergeNeighbors(units[i - 1], units[i]);          Flush();     }      private void Seed()     {         if (units[0] is Cluster)             buffer.Add((Cluster)units[0]);         else             merged.Add(units[0]);     }      private void MergeNeighbors(IUnit prev, IUnit next)     {         if (prev is Cluster)         {             if (next is Cluster)             {                 if (!prev.Description.Equals(next.Description))                 {                     Flush();                 }                  buffer.Add((Cluster)next);             }             else             {                 Flush();                 merged.Add(next);             }         }         else         {             if (next is Cluster)             {                 buffer.Add((Cluster)next);             }             else             {                 merged.Add(next);             }         }     }      private void Flush()     {         if (!buffer.Any())             return;          merged.Add(new Cluster(buffer));         buffer.Clear();     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">MergeClustersTests<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">[Fact] public void Result_WhenUnitsStartWithNonclusterAndEndWithCluster_IsCorrect() {     \/\/ Arrange     IUnit[] units = new IUnit[]     {         new Piece(&quot;some description&quot;),         new Piece(&quot;some description&quot;),         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),     };      MergeClusters sut = new MergeClusters(units);      \/\/ Act     IEnumerable&lt;IUnit&gt; actual = sut.Result;      \/\/ Assert     IUnit[] expected = new IUnit[]     {         new Piece(&quot;some description&quot;),         new Piece(&quot;some description&quot;),         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),     };      actual.Should().BeEquivalentTo(expected); }  [Fact] public void Result_WhenUnitsStartWithClusterAndEndWithCluster_IsCorrect() {     \/\/ Arrange     IUnit[] units = new IUnit[]     {         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),     };      MergeClusters sut = new MergeClusters(units);      \/\/ Act     IEnumerable&lt;IUnit&gt; actual = sut.Result;      \/\/ Assert     IUnit[] expected = new IUnit[]     {         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),     };      actual.Should().BeEquivalentTo(expected); }  [Fact] public void Result_WhenUnitsStartWithClusterAndEndWithNoncluster_IsCorrect() {     \/\/ Arrange     IUnit[] units = new IUnit[]     {         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),     };      MergeClusters sut = new MergeClusters(units);      \/\/ Act     IEnumerable&lt;IUnit&gt; actual = sut.Result;      \/\/ Assert     IUnit[] expected = new IUnit[]     {         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),     };      actual.Should().BeEquivalentTo(expected); }  [Fact] public void Result_WhenUnitsStartWithNonclusterAndEndWithNoncluster_IsCorrect() {     \/\/ Arrange     IUnit[] units = new IUnit[]     {         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),     };      MergeClusters sut = new MergeClusters(units);      \/\/ Act     IEnumerable&lt;IUnit&gt; actual = sut.Result;      \/\/ Assert     IUnit[] expected = new IUnit[]     {         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),                 new Piece(&quot;some description&quot;),             }),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),         new Cluster(             new Piece[]             {                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),                 new Piece(&quot;another description&quot;),             }),         new Piece(&quot;another description&quot;),     };      actual.Should().BeEquivalentTo(expected); } <\/code><\/pre>\n<\/div><\/div>\n<p>  \u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <i><b>void MergeNeighbors(IUnit, IUnit)<\/b><\/i> \u043a\u043b\u0430\u0441\u0441\u0430 <i><b>MergeClusters<\/b><\/i>.<\/p>\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (prev is Cluster)     {         if (next is Cluster)         {             if (!prev.Description.Equals(next.Description))             {                 Flush();             }              buffer.Add((Cluster)next);         }         else         {             Flush();             merged.Add(next);         }     }     else     {         if (next is Cluster)         {             buffer.Add((Cluster)next);         }         else         {             merged.Add(next);         }     } } <\/code><\/pre>\n<p>  \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043d\u043e \u0441 \u0434\u0440\u0443\u0433\u043e\u0439, \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u043f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043e\u0434\u0430. \u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 <i><b>Analyze &gt; Calculate Code Metrics<\/b><\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432 <i><b>Visual Studio Community<\/b><\/i>. \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"xml\">Configuration: Debug Member: MergeNeighbors(IUnit, IUnit) : void Maintainability Index: 64 Cyclomatic Complexity: 5 Class Coupling: 4 Lines of Source code: 32 Lines of Executable code: 10 <\/code><\/pre>\n<p>  <b>\u041e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0434\u0430\u043b\u0435\u0435 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/b><\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0411\u043e\u0440\u043e\u0434\u0430\u0442\u0430\u044f \u0448\u0443\u0442\u043a\u0430 \u043f\u043e \u0441\u043b\u0443\u0447\u0430\u044e<\/b>                         <\/p>\n<div class=\"spoiler_text\">#392487<br \/>  \u041c\u043d\u0435 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b\u0438 \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u044e\u0442 \u043a\u043e\u0440\u0430\u0431\u043b\u0438 \u0432 \u0431\u0443\u0442\u044b\u043b\u043a\u0430\u0445. \u0412 \u0431\u0443\u0442\u044b\u043b\u043a\u0443 \u0437\u0430\u0441\u044b\u043f\u0430\u044e\u0442 \u0441\u0438\u043b\u0438\u043a\u0430\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0435\u044f, \u0433\u043e\u0432\u043d\u0430 \u0438 \u0442\u0440\u044f\u0441\u0443\u0442. \u041f\u043e\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0448\u0442\u0443\u043a\u0438, \u0438\u043d\u043e\u0433\u0434\u0430 \u043a\u043e\u0440\u0430\u0431\u043b\u0438.<br \/>  &copy; bash.org  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h3>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433<\/h3>\n<p>  <\/p>\n<h4>\u0428\u0430\u0433 1<\/h4>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u0430\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u043b\u043e\u043a\u043e\u043c <i><b>else<\/b><\/i>, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u0431\u043b\u043e\u043a <i><b>else<\/b><\/i>.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (prev is Cluster)     {         if (next is Cluster)         {             if (!prev.Description.Equals(next.Description))             {                 Flush();             }             else             {              }              buffer.Add((Cluster)next);         }         else         {             Flush();             merged.Add(next);         }     }     else     {         if (next is Cluster)         {             buffer.Add((Cluster)next);         }         else         {             merged.Add(next);         }     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4>\u0428\u0430\u0433 2<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0441 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u043c\u0438 \u0431\u043b\u043e\u043a\u0430\u043c\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c \u043a\u0430\u0436\u0434\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043a \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u0431\u043b\u043e\u043a. \u0415\u0441\u043b\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0448\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u043b\u043e\u043a\u0443, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0431\u043b\u043e\u043a\u0430, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u0432 \u043a\u043e\u043d\u0435\u0446. \u041f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c, \u043f\u043e\u043a\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0441\u0435\u0434\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u043c\u0438 \u0431\u043b\u043e\u043a\u0430\u043c\u0438.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (prev is Cluster)     {         if (next is Cluster)         {             if (!prev.Description.Equals(next.Description))             {                 Flush();                 buffer.Add((Cluster)next);             }             else             {                 buffer.Add((Cluster)next);             }         }         else         {             Flush();             merged.Add(next);         }     }     else     {         if (next is Cluster)         {             buffer.Add((Cluster)next);         }         else         {             merged.Add(next);         }     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4>\u0428\u0430\u0433 3<\/h4>\n<p>  \u041d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 <i><b>if<\/b><\/i> \u043e\u0442\u0440\u0435\u0437\u0430\u0435\u043c \u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0439, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0431\u043b\u043e\u043a <i><b>if<\/b><\/i> \u0441 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c, \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044e \u043f\u0435\u0440\u0432\u043e\u0433\u043e <i><b>if<\/b><\/i>, \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u044c \u043d\u043e\u0432\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0432\u044b\u0440\u0435\u0437\u0430\u043d\u043d\u0443\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <i><b>else<\/b><\/i>. \u041f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e <i><b>else<\/b><\/i>.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (prev is Cluster)     {         if (next is Cluster)         {             if (!prev.Description.Equals(next.Description))             {                 Flush();                 buffer.Add((Cluster)next);             }             if (prev.Description.Equals(next.Description))             {                 {                     buffer.Add((Cluster)next);                 }             }         }         if (!(next is Cluster))         {             {                 Flush();                 merged.Add(next);             }         }     }     if (!(prev is Cluster))     {         {             if (next is Cluster)             {                 buffer.Add((Cluster)next);             }             if (!(next is Cluster))             {                 {                     merged.Add(next);                 }             }         }     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4>\u0428\u0430\u0433 4<\/h4>\n<p>  \u00ab\u0421\u0445\u043b\u043e\u043f\u044b\u0432\u0430\u0435\u043c\u00bb \u0431\u043b\u043e\u043a\u0438.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (prev is Cluster)     {         if (next is Cluster)         {             if (!prev.Description.Equals(next.Description))             {                 Flush();                 buffer.Add((Cluster)next);             }             if (prev.Description.Equals(next.Description))             {                 buffer.Add((Cluster)next);             }         }         if (!(next is Cluster))         {             Flush();             merged.Add(next);         }     }     if (!(prev is Cluster))     {         if (next is Cluster)         {             buffer.Add((Cluster)next);         }         if (!(next is Cluster))         {             merged.Add(next);         }     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4>\u0428\u0430\u0433 5<\/h4>\n<p>  \u041a \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 <i><b>if<\/b><\/i>, \u043d\u0435 \u0438\u043c\u0435\u044e\u0449\u0435\u0433\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <i><b>&amp;&amp;<\/b><\/i> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432\u0441\u0435\u0445 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0431\u043b\u043e\u043a\u043e\u0432 <i><b>if<\/b><\/i>.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (prev is Cluster)     {         if (next is Cluster)         {             if (!prev.Description.Equals(next.Description) &amp;&amp; next is Cluster &amp;&amp; prev is Cluster)             {                 Flush();                 buffer.Add((Cluster)next);             }             if (prev.Description.Equals(next.Description) &amp;&amp; next is Cluster &amp;&amp; prev is Cluster)             {                 buffer.Add((Cluster)next);             }         }         if (!(next is Cluster) &amp;&amp; prev is Cluster)         {             Flush();             merged.Add(next);         }     }     if (!(prev is Cluster))     {         if (next is Cluster &amp;&amp; !(prev is Cluster))         {             buffer.Add((Cluster)next);         }         if (!(next is Cluster) &amp;&amp; !(prev is Cluster))         {             merged.Add(next);         }     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4>\u0428\u0430\u0433 6<\/h4>\n<p>  \u041e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u043b\u043e\u043a\u0438 <i><b>if<\/b><\/i>, \u043d\u0435 \u0438\u043c\u0435\u044e\u0449\u0438\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u043e\u0432, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0438\u0445 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (!prev.Description.Equals(next.Description) &amp;&amp; next is Cluster &amp;&amp; prev is Cluster)     {         Flush();         buffer.Add((Cluster)next);     }     if (prev.Description.Equals(next.Description) &amp;&amp; next is Cluster &amp;&amp; prev is Cluster)     {         buffer.Add((Cluster)next);     }     if (!(next is Cluster) &amp;&amp; prev is Cluster)     {         Flush();         merged.Add(next);     }     if (next is Cluster &amp;&amp; !(prev is Cluster))     {         buffer.Add((Cluster)next);     }     if (!(next is Cluster) &amp;&amp; !(prev is Cluster))     {         merged.Add(next);     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4>\u0428\u0430\u0433 7<\/h4>\n<p>  \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0438\u0445 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u0434\u0435 \u0432\u044b\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0438\u0445 \u0431\u043b\u043e\u043a\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u043b\u043e\u043a\u043e\u0432 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (!prev.Description.Equals(next.Description) &amp;&amp; next is Cluster &amp;&amp; prev is Cluster)     {         Flush();     }     if (!(next is Cluster) &amp;&amp; prev is Cluster)     {         Flush();     }      if (!prev.Description.Equals(next.Description) &amp;&amp; next is Cluster &amp;&amp; prev is Cluster)     {         buffer.Add((Cluster)next);     }     if (prev.Description.Equals(next.Description) &amp;&amp; next is Cluster &amp;&amp; prev is Cluster)     {         buffer.Add((Cluster)next);     }     if (next is Cluster &amp;&amp; !(prev is Cluster))     {         buffer.Add((Cluster)next);     }      if (!(next is Cluster) &amp;&amp; prev is Cluster)     {         merged.Add(next);     }     if (!(next is Cluster) &amp;&amp; !(prev is Cluster))     {         merged.Add(next);     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4>\u0428\u0430\u0433 8<\/h4>\n<p>  \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0431\u043b\u043e\u043a\u0438 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u043a \u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <i><b>||<\/b><\/i>.  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (!prev.Description.Equals(next.Description) &amp;&amp; next is Cluster &amp;&amp; prev is Cluster ||         !(next is Cluster) &amp;&amp; prev is Cluster)     {         Flush();     }      if (!prev.Description.Equals(next.Description) &amp;&amp; next is Cluster &amp;&amp; prev is Cluster ||         prev.Description.Equals(next.Description) &amp;&amp; next is Cluster &amp;&amp; prev is Cluster ||         next is Cluster &amp;&amp; !(prev is Cluster))     {         buffer.Add((Cluster)next);     }      if (!(next is Cluster) &amp;&amp; prev is Cluster ||         !(next is Cluster) &amp;&amp; !(prev is Cluster))     {         merged.Add(next);     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4>\u0428\u0430\u0433 9<\/h4>\n<p>  \u0423\u043f\u0440\u043e\u0449\u0430\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/en.wikipedia.org\/wiki\/Boolean_algebra#Laws\" rel=\"nofollow\">\u043f\u0440\u0430\u0432\u0438\u043b \u0431\u0443\u043b\u0435\u0432\u043e\u0439 \u0430\u043b\u0433\u0435\u0431\u0440\u044b<\/a>.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (prev is Cluster &amp;&amp; !(next is Cluster &amp;&amp; prev.Description.Equals(next.Description)))     {         Flush();     }      if (next is Cluster)     {         buffer.Add((Cluster)next);     }      if (!(next is Cluster))     {         merged.Add(next);     } } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h4>\u0428\u0430\u0433 10<\/h4>\n<p>  \u0420\u0438\u0445\u0442\u0443\u0435\u043c \u043d\u0430\u043f\u0438\u043b\u044c\u043d\u0438\u043a\u043e\u043c.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (IsEndOfCompatibleClusterSequence(prev, next))         Flush();      if (next is Cluster)         buffer.Add((Cluster)next);     else         merged.Add(next); }  private static bool IsEndOfCompatibleClusterSequence(IUnit prev, IUnit next) =&gt;     prev is Cluster &amp;&amp; !(next is Cluster &amp;&amp; prev.Description.Equals(next.Description)); <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h3>\u0418\u0442\u043e\u0433\u043e<\/h3>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">private void MergeNeighbors(IUnit prev, IUnit next) {     if (IsEndOfCompatibleClusterSequence(prev, next))         Flush();      if (next is Cluster)         buffer.Add((Cluster)next);     else         merged.Add(next); } <\/code><\/pre>\n<p>  \u0410 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"xml\">Configuration: Debug Member: MergeNeighbors(IUnit, IUnit) : void Maintainability Index: 82 Cyclomatic Complexity: 3 Class Coupling: 3 Lines of Source code: 10 Lines of Executable code: 2 <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u043b\u0438\u0441\u044c, \u0430 \u043a\u043e\u0434 \u0441\u0442\u0430\u043b \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043a\u043e\u0440\u043e\u0447\u0435 \u0438 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435. \u041d\u043e \u0441\u0430\u043c\u044b\u043c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435, \u043b\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0442 \u0447\u0442\u043e: \u043a\u0442\u043e-\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u0441\u0440\u0430\u0437\u0443 \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c, \u043a\u0430\u043a \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435, \u0430 \u043a\u0442\u043e-\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u043d\u043e \u0438\u043c\u0435\u044f \u0445\u043e\u0442\u044f \u0431\u044b \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0443 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0447\u0438\u0441\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 (\u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0448\u0430\u0433\u0430) \u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e\u043c\u0443 \u0438 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u043c\u0443 \u0432\u0438\u0434\u0443.<\/p>\n<p>  <b>P.S.<\/b> <i><b>\u0412\u0441\u0435 \u043a\u0443\u0441\u043a\u0438 \u0437\u043d\u0430\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u043e\u0436\u0438\u043b\u0438\u0441\u044c \u0432 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0430\u0432\u0442\u043e\u0440\u043e\u043c \u0435\u0449\u0435 \u0432 \u0448\u043a\u043e\u043b\u0435 \u0431\u043e\u043b\u0435\u0435 15 \u043b\u0435\u0442 \u043d\u0430\u0437\u0430\u0434. \u0417\u0430 \u0447\u0442\u043e \u043e\u043d \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u0443\u044e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u044c \u0443\u0447\u0438\u0442\u0435\u043b\u044f\u043c-\u044d\u043d\u0442\u0443\u0437\u0438\u0430\u0441\u0442\u0430\u043c, \u0434\u0430\u044e\u0449\u0438\u043c \u0434\u0435\u0442\u044f\u043c \u043e\u0441\u043d\u043e\u0432\u0443 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u0422\u0430\u0442\u044c\u044f\u043d\u0430 \u0410\u043b\u0435\u043a\u0441\u0435\u0435\u0432\u043d\u0430, \u041d\u0430\u0442\u0430\u043b\u044c\u044f \u041f\u0430\u0432\u043b\u043e\u0432\u043d\u0430, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u0434\u0440\u0443\u0433 \u044d\u0442\u043e \u0447\u0438\u0442\u0430\u0435\u0442\u0435, \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0432\u0430\u043c \u0421\u041f\u0410\u0421\u0418\u0411\u041e!<\/b><\/i><\/div>\n<p> \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\/516286\/\"> https:\/\/habr.com\/ru\/post\/516286\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/516286\/\">\u041d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439 \u043f\u0440\u0438\u0435\u043c\u043e\u0432 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/refactoring.guru\/refactoring\/techniques\/simplifying-conditional-expressions\" rel=\"nofollow\">\u0442\u0443\u0442<\/a>). \u0412 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044f \u0438\u043d\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e <i>\u0437\u0430\u043c\u0435\u043d\u044b \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c<\/i> \u0438 <i>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432<\/i>. \u041e\u0431\u044b\u0447\u043d\u043e \u043e\u043d\u0430 \u0434\u0430\u0435\u0442 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0432\u0435\u0442\u043e\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043d\u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438. \u041a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 C#, \u043d\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 if\/else.<\/p>\n<p>  <a href=\"https:\/\/habr.com\/ru\/post\/516286\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ct\/22\/l9\/ct22l9tcejckodkrg0eaxyd5uv4.png\" alt=\"image\"><\/a>  <\/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-310848","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/310848","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=310848"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/310848\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=310848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=310848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=310848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}