{"id":388049,"date":"2024-06-29T07:42:09","date_gmt":"2024-06-29T07:42:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=388049"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=388049","title":{"rendered":"<span>\u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0432 C#: OrderBy.OrderBy \u0438\u043b\u0438 OrderBy.ThenBy? \u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0438 \u043f\u043e\u0447\u0435\u043c\u0443<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0430: \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043a\u043b\u044e\u0447\u0430\u043c. \u0412 C# \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0437\u043e\u0432\u043e\u0432 OrderBy().OrderBy() \u0438\u043b\u0438 OrderBy().ThenBy(). \u041d\u043e \u0432 \u0447\u0451\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438? \u0427\u0442\u043e\u0431\u044b \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/93f\/04c\/7fc\/93f04c7fc2add29c5a2e13ed2eb8f5c7.png\" alt=\"0991_OrderBy_ThenBy_ru\/image1.png\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/93f\/04c\/7fc\/93f04c7fc2add29c5a2e13ed2eb8f5c7.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0442\u0440\u0451\u0445 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u043e\u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li><strong>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/strong>. \u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043b\u044e\u0431\u0438\u0442 \u0437\u0430\u0442\u0440\u0430\u0432\u043a\u0438. \u0418\u0441\u0442\u043e\u0440\u0438\u044f \u043e \u0442\u043e\u043c, \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u043e\u043e\u0431\u0449\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0438\u0434\u0435\u044f \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0438\u0437\u0443\u0447\u0438\u0442\u044c, \u0432 \u0447\u0451\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 <em>OrderBy().OrderBy()<\/em> \u0438 <em>OrderBy().ThenBy()<\/em>.<\/li>\n<li><strong>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438<\/strong>. \u0418\u0437\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043e\u043a \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438.<\/li>\n<li><strong>\u041e\u0442\u043b\u0438\u0447\u0438\u044f \u0432 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438<\/strong>. \u041f\u043e\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 .NET \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0432 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.<a name=\"habracut\"><\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"predystoriya\">\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>\u0412\u0441\u0451 \u043d\u0430\u0447\u0430\u043b\u043e\u0441\u044c \u0441\u043e \u0441\u0442\u0430\u0442\u044c\u0438 &#171;<a href=\"https:\/\/pvs-studio.com\/ru\/blog\/posts\/csharp\/0928\/\">\u041f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0432 Unity, ASP.NET Core \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e<\/a>&#171;. \u0412 \u043d\u0435\u0439 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <em>OrderBy().OrderBy()<\/em> \u043c\u043e\u0433\u043b\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043f\u043e\u0440\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>OrderBy().OrderBy()<\/em>, \u0430 \u043d\u0435 <em>OrderBy().ThenBy()<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 <em>Wrapper<\/em> \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430: <\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">class Wrapper {   public int Primary { get; init; }   public int Secondary { get; init; } }  var arr = new Wrapper[] {   new() { Primary = 1, Secondary = 2 },   new() { Primary = 0, Secondary = 1 },   new() { Primary = 2, Secondary = 1 },   new() { Primary = 2, Secondary = 0 },   new() { Primary = 0, Secondary = 2 },   new() { Primary = 0, Secondary = 3 }, };<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e <em>Primary<\/em>, \u0437\u0430\u0442\u0435\u043c \u2013 \u043f\u043e <em>Secondary<\/em>. <\/p>\n<p>  <\/p>\n<p>\u041f\u043e \u043e\u0448\u0438\u0431\u043a\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">var sorted = arr.OrderBy(p => p.Primary)                 .OrderBy(p => p.Secondary); ....<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">Primary: 2 Secondary: 0 Primary: 0 Secondary: 1 Primary: 2 Secondary: 1 Primary: 0 Secondary: 2 Primary: 1 Secondary: 2 Primary: 0 Secondary: 3<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0437-\u0437\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0435 \u0442\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u043d\u0443\u0436\u0435\u043d. \u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <em>OrderBy().ThenBy()<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">var sorted = arr.OrderBy(p => p.Primary)                 .ThenBy(p => p.Secondary); ....<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">Primary: 0 Secondary: 1 Primary: 0 Secondary: 2 Primary: 0 Secondary: 3 Primary: 1 Secondary: 2 Primary: 2 Secondary: 0 Primary: 2 Secondary: 1<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <em>OrderBy().OrderBy()<\/em>, \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u044b \u043c\u0435\u0441\u0442\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">var sorted = arr.OrderBy(p => p.Primary)                 .OrderBy(p => p.Secondary);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">var sorted = arr.OrderBy(p => p.Secondary)                 .OrderBy(p => p.Primary);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0445\u043e\u0434\u0438\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">\/\/ #1 var sorted1 = arr.OrderBy(p => p.Secondary)                  .OrderBy(p => p.Primary);  \/\/ #2 var sorted2 = arr.OrderBy(p => p.Primary)                  .ThenBy(p => p.Secondary);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043f\u043e \u043c\u043d\u0435, \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0435. <\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0448\u044c \u0432\u044b\u0437\u043e\u0432 <em>OrderBy().OrderBy()<\/em>, \u0437\u0430\u0434\u0430\u0451\u0448\u044c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c: \u043d\u0435\u0442 \u043b\u0438 \u0432 \u043d\u0451\u043c <a href=\"https:\/\/pvs-studio.com\/ru\/blog\/examples\/v3078\/\">\u043e\u0448\u0438\u0431\u043a\u0438<\/a>? \u0421 <em>OrderBy().ThenBy()<\/em> \u0438\u043d\u0430\u0447\u0435: \u043a\u043e\u0434 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043b\u0435\u0433\u0447\u0435, \u0437\u0430\u043c\u044b\u0441\u0435\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043f\u043e\u043d\u044f\u0442\u0435\u043d.<\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0435\u0448\u043d\u0435: \u0443 \u043d\u0438\u0445 \u0440\u0430\u0437\u043d\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  <\/p>\n<h2 id=\"sravnenie-effektivnosti\">\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u043e\u0437\u044c\u043c\u0451\u043c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">struct Wrapper {   public int Primary { get; init; }   public int Secondary { get; init; } }  Wrapper[] arr = ....;  \/\/ #1 _ = arr.OrderBy(p => p.Secondary)        .OrderBy(p => p.Primary)        .ToArray();  \/\/ #2 _ = arr.OrderBy(p => p.Primary)        .ThenBy(p => p.Secondary)        .ToArray();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li><em>Wrapper<\/em> \u2013 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441 \u0434\u0432\u0443\u043c\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438. \u041e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0435\u0439 \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043e\u043a;<\/li>\n<li><em>arr<\/em> \u2013 \u043c\u0430\u0441\u0441\u0438\u0432 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 <em>Wrapper<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041a\u0430\u043a \u043e\u043d \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u2013 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0435\u0432\u0430\u0436\u043d\u043e. \u0418\u0437\u043c\u0435\u0440\u044f\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430;<\/li>\n<li>\u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438: \u043f\u0435\u0440\u0432\u044b\u0439 \u2013 \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432\u044b <em>OrderBy().OrderBy()<\/em>, \u0432\u0442\u043e\u0440\u043e\u0439 \u2013 <em>OrderBy().ThenBy()<\/em>;<\/li>\n<li>\u0432\u044b\u0437\u043e\u0432 <em>ToArray()<\/em> \u043d\u0443\u0436\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u044f \u0432\u0437\u044f\u043b \u0434\u0432\u0430 \u043d\u0430\u0431\u043e\u0440\u0430 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0442\u0438\u043f\u0430 <em>Wrapper<\/em>). \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0440\u0430\u0437\u0431\u0440\u043e\u0441 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <em>Primary<\/em> \u0438 <em>Secondary<\/em> \u0431\u043e\u043b\u044c\u0448\u0435, \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u2013 \u043c\u0435\u043d\u044c\u0448\u0435. \u0412 <em>arr<\/em> \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u043e\u0442 10 \u0434\u043e 1 000 000 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <em>Wrapper<\/em> \u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0438\u0445.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 .NET 6.<\/p>\n<p>  <\/p>\n<h3 id=\"proizvoditelnost\">\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/h3>\n<p>  <\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u0437\u043c\u0435\u0440\u044f\u043b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/benchmarkdotnet.org\/\">BenchmarkDotNet<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u0410\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0435 \u0442\u0430\u043a \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u2013 \u0432\u0430\u0436\u043d\u0430 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043e\u043a.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 #1:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>arr.Length<\/th>\n<th>10<\/th>\n<th>100<\/th>\n<th>1 000<\/th>\n<th>10 000<\/th>\n<th>100 000<\/th>\n<th>1 000 000<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>OrderBy().OrderBy()<\/td>\n<td>619 ns<\/td>\n<td>9 us<\/td>\n<td>170 us<\/td>\n<td>2 ms<\/td>\n<td>25.8 ms<\/td>\n<td>315 ms<\/td>\n<\/tr>\n<tr>\n<td>OrderBy().ThenBy()<\/td>\n<td>285 ns<\/td>\n<td>4.5 us<\/td>\n<td>100 us<\/td>\n<td>1.4 ms<\/td>\n<td>20.4 ms<\/td>\n<td>271 ms<\/td>\n<\/tr>\n<tr>\n<td><em>\u0421\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435<\/em><\/td>\n<td><em>2.17<\/em><\/td>\n<td><em>2<\/em><\/td>\n<td><em>1.7<\/em><\/td>\n<td><em>1.43<\/em><\/td>\n<td><em>1.26<\/em><\/td>\n<td><em>1.16<\/em><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 #2:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>arr.Length<\/th>\n<th>10<\/th>\n<th>100<\/th>\n<th>1 000<\/th>\n<th>10 000<\/th>\n<th>100 000<\/th>\n<th>1 000 000<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>OrderBy().OrderBy()<\/td>\n<td>553.3 ns<\/td>\n<td>8.7 us<\/td>\n<td>154 us<\/td>\n<td>2.1 ms<\/td>\n<td>29.5 ms<\/td>\n<td>364 ms<\/td>\n<\/tr>\n<tr>\n<td>OrderBy().ThenBy()<\/td>\n<td>316.4 ns<\/td>\n<td>4.2 us<\/td>\n<td>80 us<\/td>\n<td>1.1 ms<\/td>\n<td>16.9 ms<\/td>\n<td>240 ms<\/td>\n<\/tr>\n<tr>\n<td><em>\u0421\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435<\/em><\/td>\n<td><em>1.75<\/em><\/td>\n<td><em>2.07<\/em><\/td>\n<td><em>1.93<\/em><\/td>\n<td><em>1.91<\/em><\/td>\n<td><em>1.75<\/em><\/td>\n<td><em>1.52<\/em><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0439\u0442\u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0435\u0441\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0435 \u043e\u0434\u043d\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438, \u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0446\u0438\u043a\u043b\u043e\u043c <em>for<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">for (int i = 0; i &lt; iterNum; ++i) {   \/\/ Perform sorting }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 (\u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445) 1 000 000 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0442\u0438\u043f\u0430 <em>Wrapper<\/em>:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439<\/th>\n<th>1<\/th>\n<th>10<\/th>\n<th>100<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>OrderBy().OrderBy()<\/td>\n<td>0.819<\/td>\n<td>6.52<\/td>\n<td>65.15<\/td>\n<\/tr>\n<tr>\n<td>OrderBy().ThenBy()<\/td>\n<td>0.571<\/td>\n<td>5.21<\/td>\n<td>42.94<\/td>\n<\/tr>\n<tr>\n<td><em>\u0421\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435<\/em><\/td>\n<td><em>1.43<\/em><\/td>\n<td><em>1.25<\/em><\/td>\n<td><em>1.30<\/em><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0421\u043e\u0433\u043b\u0430\u0441\u0438\u0442\u0435\u0441\u044c, \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 20 \u0441\u0435\u043a\u0443\u043d\u0434 \u2013 \u043f\u043e\u0432\u043e\u0434 \u043f\u0440\u0438\u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>  <\/p>\n<h3 id=\"ispolzovanie-pamyati\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438<\/h3>\n<p>  <\/p>\n<p>\u0421 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u043f\u043e\u0445\u043e\u0436\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u2013 <em>OrderBy().OrderBy()<\/em> \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435. \u0421\u0438\u043b\u044c\u043d\u0435\u0435 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043e\u0431\u044a\u0451\u043c\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f\u0445.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u0422\u0438\u043f<\/th>\n<th>OrderBy().OrderBy()<\/th>\n<th>OrderBy().ThenBy()<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Int32[]<\/td>\n<td>4<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>Comparison&lt;Int32><\/td>\n<td>2<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>Wrapper[]<\/td>\n<td>3<\/td>\n<td>2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0418\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u044b <em>OrderBy().OrderBy()<\/em> \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442 \u043d\u0430 \u0434\u0432\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0431\u043e\u043b\u044c\u0448\u0435. \u041d\u0430 \u0442\u0435\u0441\u0442\u0435, \u0433\u0434\u0435 \u0431\u044b\u043b\u043e 100 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438, \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0440\u0430\u0437\u043d\u0438\u0446\u0435 \u0432 1\u0413\u0431 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438. <\/p>\n<p>  <\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u043c\u0435\u0440 &#171;\u043b\u0438\u0448\u043d\u0438\u0445&#187; \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432. \u041a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>  <\/p>\n<h2 id=\"otlichiya-v-povedenii\">\u041e\u0442\u043b\u0438\u0447\u0438\u044f \u0432 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438<\/h2>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c &#171;\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442&#187;. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">\/\/ #1 _ = arr.OrderBy(p => p.Secondary)        .OrderBy(p => p.Primary)        .ToArray();  \/\/ #2 _ = arr.OrderBy(p => p.Primary)        .ThenBy(p => p.Secondary)        .ToArray();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f;<\/li>\n<li>\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b;<\/li>\n<li>\u0445\u043e\u0434 \u043f\u043e\u0442\u043e\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 .NET 6 \u0432\u043e\u0437\u044c\u043c\u0451\u043c \u0441 <a href=\"https:\/\/github.com\/dotnet\/runtime\">GitHub<\/a>.<\/p>\n<p>  <\/p>\n<h3 id=\"metody-verhnego-urovnya\">\u041c\u0435\u0442\u043e\u0434\u044b \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f<\/h3>\n<p>  <\/p>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f: <em>OrderBy<\/em>, <em>ThenBy<\/em> \u0438 <em>ToArray<\/em>. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<p>  <\/p>\n<p><strong>OrderBy<\/strong><\/p>\n<p>  <\/p>\n<p><em>OrderBy<\/em> \u2013 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u0438\u043f\u0430 <em>OrderedEnumerable&lt;TElement, TKey><\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public static IOrderedEnumerable&lt;TSource>  OrderBy&lt;TSource, TKey>(this IEnumerable&lt;TSource> source,                         Func&lt;TSource, TKey> keySelector)   => new OrderedEnumerable&lt;TSource,                             TKey>(source, keySelector, null, false, null);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <em>OrderedEnumerable&lt;TElement, TKey><\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">internal OrderedEnumerable( IEnumerable&lt;TElement> source,                              Func&lt;TElement, TKey> keySelector,                              IComparer&lt;TKey>? comparer,                              bool descending,                              OrderedEnumerable&lt;TElement>? parent                            ) : base(source) {   ....   _parent = parent;   _keySelector = keySelector;   _comparer = comparer ?? Comparer&lt;TKey>.Default;   _descending = descending; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u2013 <em>base(source)<\/em>. \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u2013 <em>OrderedEnumerable&lt;TElement><\/em>. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">protected OrderedEnumerable(IEnumerable&lt;TElement> source)    => _source = source;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c: \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 <em>OrderBy<\/em> \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <em>OrderedEnumerable&lt;TElement, TKey><\/em>. \u0415\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u044f\u043c\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>_source;<\/li>\n<li>_parent;<\/li>\n<li>_keySelector;<\/li>\n<li>_comparer;<\/li>\n<li>_descending.<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>ThenBy<\/strong><\/p>\n<p>  <\/p>\n<p><em>ThenBy<\/em> \u2014 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public static IOrderedEnumerable&lt;TSource>  ThenBy&lt;TSource, TKey>(this IOrderedEnumerable&lt;TSource> source,                        Func&lt;TSource, TKey> keySelector) {   ....   return source.CreateOrderedEnumerable(keySelector, null, false); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <em>source<\/em> \u2013 <em>OrderedEnumerable&lt;TElement, TKey><\/em>. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0435\u0442\u043e\u0434\u0430 <em>CreateOrderedEnumerable<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">IOrderedEnumerable&lt;TElement>  IOrderedEnumerable&lt;TElement>  .CreateOrderedEnumerable&lt;TKey>(Func&lt;TElement, TKey> keySelector,                                  IComparer&lt;TKey>? comparer,                                  bool descending)    => new OrderedEnumerable&lt;TElement,                             TKey>(_source,                                   keySelector,                                   comparer,                                   @descending,                                   this);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u043d\u0430\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0442\u0438\u043f\u0430 <em>OrderedEnumerable&lt;TElement, TKey><\/em> (\u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0435\u0433\u043e \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043f\u0440\u043e <em>OrderBy<\/em>). \u041e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u044b\u0437\u043e\u0432\u0430, \u0438, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c: <em>ThenBy<\/em>, \u043a\u0430\u043a \u0438 <em>OrderBy<\/em>, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u0438\u043f\u0430 <em>OrderedEnumerable&lt;TElement, TKey><\/em>.<\/p>\n<p>  <\/p>\n<p><strong>ToArray<\/strong><\/p>\n<p>  <\/p>\n<p><em>ToArray<\/em> \u2013 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public static TSource[] ToArray&lt;TSource>(this IEnumerable&lt;TSource> source) {   ....   return source is IIListProvider&lt;TSource> arrayProvider     ? arrayProvider.ToArray()     : EnumerableHelpers.ToArray(source); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043e\u0431\u043e\u0438\u0445 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 <em>source<\/em> \u2013 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0442\u0438\u043f\u0430 <em>OrderedEnumerable&lt;TElement, TKey><\/em>. \u042d\u0442\u043e\u0442 \u0442\u0438\u043f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <em>IIlistProvider&lt;TSource><\/em>, \u0437\u043d\u0430\u0447\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0439\u0434\u0451\u0442 \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 <em>arrayProvider.ToArray()<\/em>. \u041f\u043e \u0444\u0430\u043a\u0442\u0443 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u043c\u0435\u0442\u043e\u0434 <em>OrderedEnumerable&lt;TElement>.ToArray<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public TElement[] ToArray() {   Buffer&lt;TElement> buffer = new Buffer&lt;TElement>(_source);    int count = buffer._count;   if (count == 0)   {     return buffer._items;   }    TElement[] array = new TElement[count];   int[] map = SortedMap(buffer);   for (int i = 0; i != array.Length; i++)   {     array[i] = buffer._items[map[i]];   }    return array; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u0437\u0434\u0435\u0441\u044c \u043d\u0430\u0447\u043d\u0443\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f. \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435, \u043d\u0443\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<h3 id=\"sostoyaniya-obektov-orderedenumerable\">\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 OrderedEnumerable<\/h3>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">\/\/ #1 _ = arr.OrderBy(p => p.Secondary) \/\/ Wrapper[] -> #1.1        .OrderBy(p => p.Primary)   \/\/ #1.1 -> #1.2        .ToArray();                \/\/ #1.2 -> Wrapper[]  \/\/ #2 _ = arr.OrderBy(p => p.Primary)  \/\/ Wrapper[] -> #2.1        .ThenBy(p => p.Secondary) \/\/ #2.1 -> #2.2        .ToArray();               \/\/ #2.2 -> Wrapper[]<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0443\u0436\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043f\u043e\u043f\u0430\u0440\u043d\u043e \u0447\u0435\u0442\u044b\u0440\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li>#1.1 \u0438 #2.1 \u2013 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043f\u043e\u0440\u043e\u0436\u0434\u0451\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0432\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 <em>OrderBy<\/em> \u0432 \u043e\u0431\u043e\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445;<\/li>\n<li>#1.2 \u0438 #2.2 \u2013 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043f\u043e\u0440\u043e\u0436\u0434\u0451\u043d\u043d\u044b\u0435 \u0432\u0442\u043e\u0440\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c <em>OrderBy<\/em> \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438 <em>ThenBy<\/em> \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c 2 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043f\u043e\u0440\u043e\u0436\u0434\u0451\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0432\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 <em>OrderBy<\/em>:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041f\u043e\u043b\u0435<\/th>\n<th>Object #1.1<\/th>\n<th>Object #2.1<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>_source<\/td>\n<td>arr<\/td>\n<td>arr<\/td>\n<\/tr>\n<tr>\n<td>_comparer<\/td>\n<td>Comparer&lt;Int32>.Default<\/td>\n<td>Comparer&lt;Int32>.Default<\/td>\n<\/tr>\n<tr>\n<td>_descending<\/td>\n<td>false<\/td>\n<td>false<\/td>\n<\/tr>\n<tr>\n<td>_keySelector<\/td>\n<td>p => p.Secondary<\/td>\n<td>p => p.Primary<\/td>\n<\/tr>\n<tr>\n<td>_parent<\/td>\n<td>null<\/td>\n<td>null<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u042d\u0442\u0430 \u043f\u0430\u0440\u0430 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0430. \u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u2013 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u044b.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043f\u043e\u0440\u043e\u0436\u0434\u0451\u043d\u043d\u044b\u0445 \u0432\u0442\u043e\u0440\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c <em>OrderBy<\/em> (#1.2) \u0438 <em>ThenBy<\/em> (#2.2):<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041f\u043e\u043b\u0435<\/th>\n<th>Object #1.2<\/th>\n<th>Object #2.2<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>_source<\/td>\n<td><strong>Object #1.1<\/strong><\/td>\n<td><strong>arr<\/strong><\/td>\n<\/tr>\n<tr>\n<td>_comparer<\/td>\n<td>Comparer&lt;Int32>.Default<\/td>\n<td>Comparer&lt;Int32>.Default<\/td>\n<\/tr>\n<tr>\n<td>_descending<\/td>\n<td>false<\/td>\n<td>false<\/td>\n<\/tr>\n<tr>\n<td>_keySelector<\/td>\n<td>p => p.Primary<\/td>\n<td>p => p.Secondary<\/td>\n<\/tr>\n<tr>\n<td>_parent<\/td>\n<td><strong>null<\/strong><\/td>\n<td><strong>Object #2.1<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0421\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u044b \u0442\u043e\u0436\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f, \u044d\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e. \u0427\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u2013 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u043b\u044f <em>_source<\/em> \u0438 <em>_parent<\/em>. \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c <em>ThenBy<\/em> (#2.2): \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0435\u0441\u0442\u044c &#171;\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c&#187; \u2013 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.<\/p>\n<p>  <\/p>\n<h3 id=\"potok-ispolneniya\">\u041f\u043e\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u043a\u0430\u043a \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043f\u043e\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. <\/p>\n<p>  <\/p>\n<p>\u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043c\u0435\u0442\u043e\u0434\u0443 <em>ToArray<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public TElement[] ToArray() {   Buffer&lt;TElement> buffer = new Buffer&lt;TElement>(_source);    int count = buffer._count;   if (count == 0)   {     return buffer._items;   }    TElement[] array = new TElement[count];   int[] map = SortedMap(buffer);   for (int i = 0; i != array.Length; i++)   {     array[i] = buffer._items[map[i]];   }    return array; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 <em>_source<\/em> \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li><em>OrderBy().OrderBy()<\/em>: \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <em>OrderedEnumerable&lt;TElement, TKey><\/em>;<\/li>\n<li><em>OrderBy().ThenBy()<\/em>: \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <em>Wrapper[]<\/em>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <em>Buffer&lt;TElement><\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">internal readonly struct Buffer&lt;TElement> {   internal readonly TElement[] _items;   internal readonly int _count;    internal Buffer(IEnumerable&lt;TElement> source)   {     if (source is IIListProvider&lt;TElement> iterator)     {       TElement[] array = iterator.ToArray();       _items = array;       _count = array.Length;     }     else     {       _items = EnumerableHelpers.ToArray(source, out _count);     }   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0432 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <em>OrderBy().OrderBy()<\/em> \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0438\u0434\u0451\u0442 \u043f\u043e then-\u0432\u0435\u0442\u0432\u0438, \u0442\u0430\u043a \u043a\u0430\u043a <em>OrderedEnumerable<\/em> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <em>IIListProvider&lt;TElement><\/em>;<\/li>\n<li>\u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u0432 <em>OrderBy().ThenBy()<\/em> \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0438\u0434\u0451\u0442 \u043f\u043e else-\u0432\u0435\u0442\u0432\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u044b (<em>Wrapper[]<\/em> \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435) \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434 <em>ToArray<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u0432\u044b\u0448\u0435. \u0418\u0437 \u043d\u0435\u0433\u043e \u043e\u043f\u044f\u0442\u044c \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <em>Buffer<\/em>, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0443\u0436\u0435 \u043f\u043e\u0439\u0434\u0451\u0442 \u043f\u043e else-\u0432\u0435\u0442\u043a\u0435, \u0442.\u043a. <em>_source<\/em> \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 #1.1 \u2013 <em>Wrapper[]<\/em>.<\/p>\n<p>  <\/p>\n<p><em>EnumerableHelpers.ToArray<\/em> \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043a\u043e\u043f\u0438\u044e \u043c\u0430\u0441\u0441\u0438\u0432\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">internal static T[] ToArray&lt;T>(IEnumerable&lt;T> source, out int length) {   if (source is ICollection&lt;T> ic)   {     int count = ic.Count;     if (count != 0)     {               T[] arr = new T[count];       ic.CopyTo(arr, 0);       length = count;       return arr;     }   }   else     ....    .... }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0438\u0434\u0451\u0442 \u043f\u043e then-\u0432\u0435\u0442\u043a\u0435. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 \u044f \u043e\u043f\u0443\u0441\u0442\u0438\u043b, \u0442.\u043a. \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d \u043d\u0435\u0432\u0430\u0436\u0435\u043d.<\/p>\n<p>  <\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0432\u0438\u0434\u043d\u043e \u043f\u043e \u0441\u0442\u0435\u043a\u0430\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 &#171;\u043b\u0438\u0448\u043d\u0438\u0435&#187; \u0432\u044b\u0437\u043e\u0432\u044b:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>Call stack \u0434\u043b\u044f OrderBy().OrderBy()<\/th>\n<th>Call stack \u0434\u043b\u044f OrderBy().ThenBy()<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>EnumerableHelpers.ToArray<\/td>\n<td>EnumerableHelpers.ToArray<\/td>\n<\/tr>\n<tr>\n<td><strong>Buffer.ctor<\/strong><\/td>\n<td>Buffer.ctor<\/td>\n<\/tr>\n<tr>\n<td><strong>OrderedEnumerable.ToArray<\/strong><\/td>\n<td>OrderedEnumerable.ToArray<\/td>\n<\/tr>\n<tr>\n<td>Buffer.ctor<\/td>\n<td>Enumerable.ToArray<\/td>\n<\/tr>\n<tr>\n<td>OrderedEnumerable.ToArray<\/td>\n<td>Main<\/td>\n<\/tr>\n<tr>\n<td>Enumerable.ToArray<\/td>\n<\/tr>\n<tr>\n<td>Main<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041e\u0442\u0441\u044e\u0434\u0430, \u043a\u0441\u0442\u0430\u0442\u0438, \u0438 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0412\u044b\u0448\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441 \u043d\u0438\u043c\u0438:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u0422\u0438\u043f<\/th>\n<th>OrderBy().OrderBy()<\/th>\n<th>OrderBy().ThenBy()<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Int32[]<\/td>\n<td>4<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>Comparison&lt;Int32><\/td>\n<td>2<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>Wrapper[]<\/td>\n<td>3<\/td>\n<td>2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438 \u0437\u0434\u0435\u0441\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u044b: <em>Int32[]<\/em> \u0438 <em>Wrapper[]<\/em>. \u041e\u043d\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043b\u0438\u0448\u043d\u0438\u0439 \u0440\u0430\u0437 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 <em>OrderedEnumerable&lt;TElement>.ToArray<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public TElement[] ToArray() {   ....   TElement[] array = new TElement[count];   int[] map = SortedMap(buffer);   .... }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0449\u0451 \u0440\u0430\u0437 \u043e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 <em>array<\/em> \u0438 <em>map<\/em> \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438: \u0447\u0435\u043c \u043e\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435, \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0432\u0435\u0440\u0445\u0435\u0434 \u0438\u0437-\u0437\u0430 \u043b\u0438\u0448\u043d\u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <em>OrderedEnumerable&lt;TElement>.ToArray<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430 \u0436\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e. \u0415\u0449\u0451 \u0440\u0430\u0437 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043a\u043e\u0434 \u043c\u0435\u0442\u043e\u0434\u0430 <em>OrderedEnumerable&lt;TElement>.ToArray<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public TElement[] ToArray() {   Buffer&lt;TElement> buffer = new Buffer&lt;TElement>(_source);    int count = buffer._count;   if (count == 0)   {     return buffer._items;   }    TElement[] array = new TElement[count];   int[] map = SortedMap(buffer);   for (int i = 0; i != array.Length; i++)   {     array[i] = buffer._items[map[i]];   }    return array; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 <em>map<\/em>. \u041e\u043d \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u0445:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0438\u043d\u0434\u0435\u043a\u0441 \u2013 \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435;<\/li>\n<li>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u2013 \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, <em>map[5] == 62<\/em>. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 62 \u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u0430 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 5.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e &#171;\u043a\u0430\u0440\u0442\u0443 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0439&#187;, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <em>SortedMap:<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">private int[] SortedMap(Buffer&lt;TElement> buffer)    => GetEnumerableSorter().Sort(buffer._items, buffer._count);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <em>GetEnumerableSorter<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">private EnumerableSorter&lt;TElement> GetEnumerableSorter()    => GetEnumerableSorter(null);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0443 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">internal override EnumerableSorter&lt;TElement>  GetEnumerableSorter(EnumerableSorter&lt;TElement>? next) {   ....    EnumerableSorter&lt;TElement> sorter =      new EnumerableSorter&lt;TElement, TKey>(_keySelector,                                           comparer,                                           _descending,                                           next);   if (_parent != null)   {     sorter = _parent.GetEnumerableSorter(sorter);   }    return sorter; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u0435\u0442 \u0435\u0449\u0451 \u043e\u0434\u043d\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c:<\/p>\n<p>  <\/p>\n<ul>\n<li><em>OrderBy().OrderBy()<\/em>: <em>_parent<\/em> \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 #1.2 \u2013 <em>null<\/em>. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <em>EnumerableSorter<\/em>.<\/li>\n<li><em>OrderBy().ThenBy()<\/em>: <em>_parent<\/em> \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 #2.2 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 #2.1. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0434\u0432\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <em>EnumerableSorter<\/em>, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0441\u0447\u0451\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u2013 <em>_parent.GetEnumerableSorter(sorter)<\/em>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <em>EnumerableSorter<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">internal EnumerableSorter(   Func&lt;TElement, TKey> keySelector,    IComparer&lt;TKey> comparer,    bool descending,    EnumerableSorter&lt;TElement>? next) {   _keySelector = keySelector;   _comparer = comparer;   _descending = descending;   _next = next; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0441\u0451, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u2013 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0415\u0441\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u043e \u043f\u043e\u043b\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u2013 <em>_keys<\/em>. \u041e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043f\u043e\u0437\u0436\u0435, \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <em>ComputeKeys<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0437\u0430 \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0442 \u043f\u043e\u043b\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u0437 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">_ = arr.OrderBy(p => p.Primary)        .ThenBy(p => p.Secondary)        .ToArray();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>OrderBy<\/em> \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <em>EnumerableSorter<\/em>. \u0415\u0433\u043e \u043f\u043e\u043b\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li><em>_keySelector<\/em>: \u0434\u0435\u043b\u0435\u0433\u0430\u0442, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 \u043a\u043b\u044e\u0447. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435: <em>Wrapper<\/em> -> <em>int<\/em>. \u0414\u0435\u043b\u0435\u0433\u0430\u0442: <em>p => p.Primary<\/em>;<\/li>\n<li><em>_comparer<\/em>: \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0439. <em>Comparer&lt;T>.Default<\/em>, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0437\u0430\u0434\u0430\u043d \u044f\u0432\u043d\u043e;<\/li>\n<li><em>_descenging<\/em>: \u0444\u043b\u0430\u0433 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044e;<\/li>\n<li><em>_next<\/em>: \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 <em>EnumerableSorter<\/em>, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u2013 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u043d \u0434\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044e \u0438\u0437 <em>ThenBy<\/em>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <em>EnumerableSorter<\/em> \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d, \u0443 \u043d\u0435\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <em>Sort<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">private int[] SortedMap(Buffer&lt;TElement> buffer)    => GetEnumerableSorter().Sort(buffer._items, buffer._count);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043b\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <em>Sort<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">internal int[] Sort(TElement[] elements, int count) {   int[] map = ComputeMap(elements, count);   QuickSort(map, 0, count - 1);   return map; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <em>ComputeMap<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">private int[] ComputeMap(TElement[] elements, int count) {   ComputeKeys(elements, count);   int[] map = new int[count];   for (int i = 0; i &lt; map.Length; i++)   {     map[i] = i;   }    return map; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 <em>ComputeKeys<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">internal override void ComputeKeys(TElement[] elements, int count) {   _keys = new TKey[count];   for (int i = 0; i &lt; count; i++)   {     _keys[i] = _keySelector(elements[i]);   }    _next?.ComputeKeys(elements, count); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 <em>_keys<\/em> \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <em>EnumerableSorter<\/em>. \u0412\u044b\u0437\u043e\u0432 <em>_next?.ComputeKeys(elements, count)<\/em> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u044e \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <em>EnumerableSorter<\/em>.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0435 <em>_keys<\/em>? \u042d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0445\u0440\u0430\u043d\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432\u044b\u0437\u043e\u0432\u0430 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043b\u044e\u0447\u0435\u0439, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">var arr = new Wrapper[] {   new() { Primary = 3, Secondary = 2 },   new() { Primary = 3, Secondary = 1 },   new() { Primary = 1, Secondary = 0 } };  _ = arr.OrderBy(p => p.Primary)        .ThenBy(p => p.Secondary)        .ToArray();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0434\u0432\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <em>EnumerableSorter<\/em>.<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041f\u043e\u043b\u0435<\/th>\n<th>EnumerableSorter #1<\/th>\n<th>EnumerableSorter #2<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>_keySelector<\/td>\n<td>p => p.Primary<\/td>\n<td>p => p.Secondary<\/td>\n<\/tr>\n<tr>\n<td>_keys<\/td>\n<td>[3, 3, 1]<\/td>\n<td>[2, 1, 0]<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, <em>_keys<\/em> \u0445\u0440\u0430\u043d\u0438\u0442 \u043a\u043b\u044e\u0447\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u043c\u0435\u0442\u043e\u0434 <em>ComputeMap<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">private int[] ComputeMap(TElement[] elements, int count) {   ComputeKeys(elements, count);   int[] map = new int[count];   for (int i = 0; i &lt; map.Length; i++)   {     map[i] = i;   }    return map; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <em>ComputeKeys<\/em> \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 <em>map<\/em>. \u042d\u0442\u043e \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u0445. \u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u043e\u043d \u043f\u043e\u043a\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u043a i -> i, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0435\u0449\u0451 \u0432\u044b\u0448\u0435 \u2013 \u0432 \u043c\u0435\u0442\u043e\u0434 <em>Sort<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">internal int[] Sort(TElement[] elements, int count) {   int[] map = ComputeMap(elements, count);   QuickSort(map, 0, count - 1);   return map; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <em>QuickSort<\/em>, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432 <em>map<\/em> \u043f\u0440\u0438\u043c\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u0438\u0434. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0438 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u043c.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043b\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <em>QuickSort<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">protected override void QuickSort(int[] keys, int lo, int hi)    => new Span&lt;int>(keys, lo, hi - lo + 1).Sort(CompareAnyKeys);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0434\u0435\u0442\u0430\u043b\u0438 <em>Span<\/em> \u0438 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <em>Sort<\/em> \u043f\u043e\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u043c. \u041e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043d\u0430 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 <em>Comparison<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">public delegate int Comparison&lt;in T>(T x, T y);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0434\u0435\u043b\u0435\u0433\u0430\u0442 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f. \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0438\u0445 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<p>  <\/p>\n<ul>\n<li>&lt; 0, \u0435\u0441\u043b\u0438 <em>x<\/em> \u043c\u0435\u043d\u044c\u0448\u0435 <em>y<\/em>;<\/li>\n<li>0, \u0435\u0441\u043b\u0438 <em>x<\/em> \u0440\u0430\u0432\u0435\u043d <em>y<\/em>;<\/li>\n<li>> 0, \u0435\u0441\u043b\u0438 <em>x<\/em> \u0431\u043e\u043b\u044c\u0448\u0435 <em>y<\/em>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <em>CompareAnyKeys<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">internal override int CompareAnyKeys(int index1, int index2) {   Debug.Assert(_keys != null);    int c = _comparer.Compare(_keys[index1], _keys[index2]);   if (c == 0)   {     if (_next == null)     {       return index1 - index2; \/\/ ensure stability of sort     }      return _next.CompareAnyKeys(index1, index2);   }    \/\/ ....   return (_descending != (c > 0)) ? 1 : -1; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0435\u0433\u043e \u043f\u043e \u043a\u0443\u0441\u043e\u0447\u043a\u0430\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">int c = _comparer.Compare(_keys[index1], _keys[index2]); if (c == 0)   ....  return (_descending != (c > 0)) ? 1 : -1;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440, \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432 <em>_comparer<\/em>. \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u044f\u0432\u043d\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440\u0430 \u043d\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u043b\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <em>Comparer&lt;T>.Default<\/em>, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2013 <em>Comparer&lt;Int32>.Default<\/em>. <\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043d\u0435 \u0440\u0430\u0432\u043d\u044b, \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <em>c == 0<\/em> \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u0438 \u043f\u043e\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u0434\u0451\u0442 \u0432 <em>return<\/em>. \u041f\u043e\u043b\u0435 <em>_descending<\/em> \u0445\u0440\u0430\u043d\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430: \u043f\u043e \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044e \u0438\u043b\u0438 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e. \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e, \u0437\u0430 \u0441\u0447\u0451\u0442 \u043d\u0435\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0432\u043d\u044b?<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">if (c == 0) {   if (_next == null)   {     return index1 - index2; \/\/ ensure stability of sort   }    return _next.CompareAnyKeys(index1, index2); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0432 \u0438\u0433\u0440\u0443 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 <em>EnumerableSorter<\/em>, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c. \u0415\u0441\u043b\u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u043a\u043b\u044e\u0447\u0438 \u0440\u0430\u0432\u043d\u044b, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u2013 \u0430 \u043d\u0435\u0442 \u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0435\u0432 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438? \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c (<em>_next != null<\/em>), \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0443\u0436\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u043d\u0438\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0437\u0430 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 <em>Sort<\/em> \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 <em>OrderBy().OrderBy()<\/em>? \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043d\u0430\u0437\u0430\u0434, \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <em>EnumerableSorter<\/em>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cs\">internal override EnumerableSorter&lt;TElement>  GetEnumerableSorter(EnumerableSorter&lt;TElement>? next) {   ....    EnumerableSorter&lt;TElement> sorter =      new EnumerableSorter&lt;TElement, TKey>(_keySelector,                                           comparer,                                           _descending,                                           next);   if (_parent != null)   {     sorter = _parent.GetEnumerableSorter(sorter);   }    return sorter; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <em>_parent<\/em> \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <em>OrderBy,<\/em> \u2013 <em>null<\/em>. \u0417\u043d\u0430\u0447\u0438\u0442, \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <em>EnumerableSorter<\/em>. \u041e\u043d \u043d\u0438 \u0441 \u0447\u0435\u043c \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <em>_next<\/em> \u2013 <em>null<\/em>. <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0432\u0441\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430. \u041a\u0430\u043a \u044d\u0442\u043e \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043c\u044b \u0443\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438. \u0427\u0442\u043e\u0431\u044b \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u043f\u0440\u043e\u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e \u043e\u0434\u043d\u0443 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446, \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435.<\/p>\n<p>  <\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 (\u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445) 1 000 000 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0442\u0438\u043f\u0430 <em>Wrapper<\/em>:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439<\/th>\n<th>1<\/th>\n<th>10<\/th>\n<th>100<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>OrderBy().OrderBy()<\/td>\n<td>0.819<\/td>\n<td>6.52<\/td>\n<td>65.15<\/td>\n<\/tr>\n<tr>\n<td>OrderBy().ThenBy()<\/td>\n<td>0.571<\/td>\n<td>5.21<\/td>\n<td>42.94<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<h2 id=\"raznica-v-dvuh-slovah\">\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445<\/h2>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b <em>OrderBy<\/em> \u0438 <em>ThenBy<\/em> \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b <em>OrderedEnumerable<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438. \u041f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0442\u0438\u043f\u0430 <em>EnumerableSorter<\/em>. \u0418\u043c\u0435\u043d\u043d\u043e \u043e\u043d\u0438 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u044b \u0438 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440.<\/p>\n<p>  <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 <em>OrderBy().OrderBy()<\/em> \u0438 <em>OrderBy().ThenBy()<\/em> \u2013 \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p><strong>OrderBy().OrderBy()<\/strong>. \u0421\u0432\u044f\u0437\u0435\u0439 \u043d\u0435\u0442 \u043d\u0438 \u043c\u0435\u0436\u0434\u0443 <em>OrderedEnumerable<\/em>, \u043d\u0438 \u043c\u0435\u0436\u0434\u0443 <em>EnumerableSorter<\/em>. \u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f &#171;\u043b\u0438\u0448\u043d\u0438\u0435&#187; \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u0432\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438, \u0430 \u043d\u0435 \u043e\u0434\u043d\u0430. \u0420\u0430\u0441\u0445\u043e\u0434\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435.<\/p>\n<p>  <\/p>\n<p><strong>OrderBy().ThenBy()<\/strong>. \u0418 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b <em>OrderedEnumerable<\/em>, \u0438 <em>EnumerableSorter<\/em> \u0441\u0432\u044f\u0437\u0430\u043d\u044b. \u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f\u043c. \u041b\u0438\u0448\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f. \u041f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u043d\u044c\u0448\u0435, \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"vyvody\">\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<p>  <\/p>\n<p>\u041a\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c <em>OrderBy().ThenBy()<\/em> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u043e <em>OrderBy().OrderBy()<\/em>:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043b\u0443\u0447\u0448\u0435 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f;<\/li>\n<li>\u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d \u043e\u0448\u0438\u0431\u043a\u0430\u043c;<\/li>\n<li>\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435;<\/li>\n<li>\u0440\u0430\u0441\u0445\u043e\u0434\u0443\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 <a href=\"https:\/\/twitter.com\/_SergVasiliev_\">Twitter<\/a>, \u0435\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438.<\/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\/articles\/689216\/\"> https:\/\/habr.com\/ru\/articles\/689216\/<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0430: \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043a\u043b\u044e\u0447\u0430\u043c. \u0412 C# \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0437\u043e\u0432\u043e\u0432 OrderBy().OrderBy() \u0438\u043b\u0438 OrderBy().ThenBy(). \u041d\u043e \u0432 \u0447\u0451\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438? \u0427\u0442\u043e\u0431\u044b \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/93f\/04c\/7fc\/93f04c7fc2add29c5a2e13ed2eb8f5c7.png\" alt=\"0991_OrderBy_ThenBy_ru\/image1.png\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/93f\/04c\/7fc\/93f04c7fc2add29c5a2e13ed2eb8f5c7.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0442\u0440\u0451\u0445 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u043e\u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li><strong>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/strong>. \u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043b\u044e\u0431\u0438\u0442 \u0437\u0430\u0442\u0440\u0430\u0432\u043a\u0438. \u0418\u0441\u0442\u043e\u0440\u0438\u044f \u043e \u0442\u043e\u043c, \u043e\u0442\u043a\u0443\u0434\u0430 \u0432\u043e\u043e\u0431\u0449\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0438\u0434\u0435\u044f \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0438\u0437\u0443\u0447\u0438\u0442\u044c, \u0432 \u0447\u0451\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 <em>OrderBy().OrderBy()<\/em> \u0438 <em>OrderBy().ThenBy()<\/em>.<\/li>\n<li><strong>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438<\/strong>. \u0418\u0437\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043e\u043a \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438.<\/li>\n<li><strong>\u041e\u0442\u043b\u0438\u0447\u0438\u044f \u0432 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438<\/strong>. \u041f\u043e\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 .NET \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0432 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.<br \/>\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-388049","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/388049","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=388049"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/388049\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=388049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=388049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=388049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}