{"id":415763,"date":"2024-06-30T00:33:54","date_gmt":"2024-06-30T00:33:54","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=415763"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-30T00:33:54","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=415763","title":{"rendered":"<span>Except \u0432 Linq<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043a\u043e\u0434\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u00ab\u043d\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u0442\u044b \u043e\u0442 \u043d\u0435\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0448\u044c\u00bb. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0438 \u043f\u043e\u0434\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u043e \u043c\u0435\u043d\u044f \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u043f\u044b\u0442\u0430\u044e\u0441\u044c \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 Except \u0432 Linq \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d, \u0430 \u043d\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u044f \u0445\u043e\u0447\u0443.<\/p>\n<hr\/>\n<p>\u0427\u0442\u043e, \u043f\u043e \u0432\u0430\u0448\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e, \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cs\">var documentsDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));  FileInfo[] FirstDirrectoryFiles = documentsDir.GetFiles();  FileInfo[] SecondDirrectoryFiles = documentsDir.GetFiles();  foreach (FileInfo item in FirstDirrectoryFiles.Except(SecondDirrectoryFiles))  {  Console.WriteLine(item.Name);  }<\/code><\/pre>\n<p>\u042f \u0432\u043e\u0442 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043b, \u0447\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e Except \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0447\u0438\u0442\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e (IEnumerable) \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 (IEnumerable) \u043b\u0435\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432\u043e\u043f\u0440\u0435\u043a\u0438 \u043c\u043e\u0438\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f\u043c \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0d6\/333\/ad6\/0d6333ad685f2fb91312af2d78cb203b.png\" width=\"408\" height=\"93\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0d6\/333\/ad6\/0d6333ad685f2fb91312af2d78cb203b.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043d\u0435 \u0432\u0441\u044f\u043a\u043e\u0433\u043e \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f (\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 .NET 5 \u0438 \u0432 .NET 6 \u2014 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d). \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0438 \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <a href=\"https:\/\/docs.microsoft.com\/ru-ru\/dotnet\/api\/system.linq.enumerable.except?view=net-6.0\" rel=\"noopener noreferrer nofollow\">Except<\/a>. \u0422\u0430\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u00ab\u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438\u00bb \u0438 \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Except&lt;TSource>(IEnumerable&lt;TSource>,   IEnumerable&lt;TSource>)<\/p>\n<\/td>\n<td>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u0442   \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043b\u044f   \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Except&lt;TSource>(IEnumerable&lt;TSource>,   IEnumerable&lt;TSource>, IEqualityComparer&lt;TSource>)<\/p>\n<\/td>\n<td>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u0442   \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043b\u044f   \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 IEqualityComparer&lt;T>.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0430\u0448 \u043a\u043e\u0434 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a, \u043a\u0430\u043a \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b, \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/dotnet\/runtime\/\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/dotnet\/runtime\/<\/a> \u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043c\u0435\u0442\u043e\u0434\u0430 Except.<\/p>\n<p>\u041d\u0430\u0448\u0430 <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/a7c69745a4e22757c69f65d2a750e2d6923e1186\/src\/libraries\/System.Linq\/src\/System\/Linq\/Except.cs#L10\" rel=\"noopener noreferrer nofollow\">\u0442\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430<\/a>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/929\/832\/cb3\/929832cb340b88b3e708bd858e5cea5c.png\" width=\"624\" height=\"184\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/929\/832\/cb3\/929832cb340b88b3e708bd858e5cea5c.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public static IEnumerable&lt;TSource> Except&lt;TSource>(this IEnumerable&lt;TSource> first, IEnumerable&lt;TSource> second) {             if (first == null)             {                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);             }              if (second == null)             {                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);             }              return ExceptIterator(first, second, null); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0432 <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/a7c69745a4e22757c69f65d2a750e2d6923e1186\/src\/libraries\/System.Linq\/src\/System\/Linq\/Except.cs#L79\" rel=\"noopener noreferrer nofollow\">ExceptIterator<\/a>.<\/p>\n<p>\u0421\u0442\u0440\u043e\u0433\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u043c\u0435\u0442\u043e\u0434 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0442\u0430\u043a\u0436\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c35\/dc9\/4af\/c35dc94af8110a0b1975bb418c60e926.png\" width=\"624\" height=\"174\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c35\/dc9\/4af\/c35dc94af8110a0b1975bb418c60e926.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public static IEnumerable&lt;TSource> Except&lt;TSource>(this IEnumerable&lt;TSource> first, IEnumerable&lt;TSource> second, IEqualityComparer&lt;TSource>? comparer) {             if (first == null)             {                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);             }              if (second == null)             {                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);             }              return ExceptIterator(first, second, comparer); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430, \u0430 \u043d\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e? \u0421\u0438\u043b\u0430\u043c\u0438 <a href=\"https:\/\/t.me\/dotnettalks\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430<\/a> \u0431\u044b\u043b\u043e \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0434\u0435\u043b\u043e \u0432 <a href=\"https:\/\/coding.abel.nu\/2014\/07\/adding-an-overload-is-a-breaking-change\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u043c<\/a> \u0438 <a href=\"https:\/\/rules.sonarsource.com\/csharp\/RSPEC-2360\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u043c<\/a>.<\/p>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a\u043e\u0434 <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/a7c69745a4e22757c69f65d2a750e2d6923e1186\/src\/libraries\/System.Linq\/src\/System\/Linq\/Except.cs#L79\" rel=\"noopener noreferrer nofollow\">ExceptIterator<\/a>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/91b\/711\/bb7\/91b711bb75131aba6b85a65c9c772356.png\" width=\"624\" height=\"139\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/91b\/711\/bb7\/91b711bb75131aba6b85a65c9c772356.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">private static IEnumerable&lt;TSource> ExceptIterator&lt;TSource>(IEnumerable&lt;TSource> first, IEnumerable&lt;TSource> second, IEqualityComparer&lt;TSource>? comparer) {             var set = new HashSet&lt;TSource>(second, comparer);              foreach (TSource element in first)             {                 if (set.Add(element))                 {                     yield return element;                 }             } }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0418\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/libraries\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/HashSet.cs#L55\" rel=\"noopener noreferrer nofollow\">\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/a>. \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430.<\/p>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430: \u00a0<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4d0\/d60\/215\/4d0d602153056d525ae5e3663db4ca48.png\" width=\"519\" height=\"105\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4d0\/d60\/215\/4d0d602153056d525ae5e3663db4ca48.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 \u0440\u0430\u0432\u0435\u043d null, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e Default \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 EqualityComparer.  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/937\/835\/238\/937835238ffb0493644ac1607b73c294.png\" width=\"624\" height=\"228\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/937\/835\/238\/937835238ffb0493644ac1607b73c294.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public HashSet(IEqualityComparer&lt;T>? comparer) {             if (comparer is not null &amp;&amp; comparer != EqualityComparer&lt;T>.Default) \/\/ first check for null to avoid forcing default comparer instantiation unnecessarily             {                 _comparer = comparer;             }              \/\/ Special-case EqualityComparer&lt;string>.Default, StringComparer.Ordinal, and StringComparer.OrdinalIgnoreCase.             \/\/ We use a non-randomized comparer for improved perf, falling back to a randomized comparer if the             \/\/ hash buckets become unbalanced.             if (typeof(T) == typeof(string))             {                 IEqualityComparer&lt;string>? stringComparer = NonRandomizedStringEqualityComparer.GetStringComparer(_comparer);                 if (stringComparer is not null)                 {                     _comparer = (IEqualityComparer&lt;T>?)stringComparer;                 }             } }<\/code><\/pre>\n<\/div>\n<\/details>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/353\/5c9\/508\/3535c95083629ed6ccdc7a9d4f874d17.png\" width=\"624\" height=\"327\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/353\/5c9\/508\/3535c95083629ed6ccdc7a9d4f874d17.png\"\/><figcaption><\/figcaption><\/figure>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/coreclr\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/EqualityComparer.CoreCLR.cs#L10\" rel=\"noopener noreferrer nofollow\">\u0422\u0443\u0442<\/a>, \u043d\u0430 \u043c\u043e\u0439 \u0441\u043a\u0440\u043e\u043c\u043d\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0432\u0441\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e:  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/daf\/468\/275\/daf468275f73af96a451bd04cdbea980.png\" width=\"624\" height=\"75\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/daf\/468\/275\/daf468275f73af96a451bd04cdbea980.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public abstract partial class EqualityComparer&lt;T> : IEqualityComparer, IEqualityComparer&lt;T> {         \/\/ To minimize generic instantiation overhead of creating the comparer per type, we keep the generic portion of the code as small         \/\/ as possible and define most of the creation logic in a non-generic class.         public static EqualityComparer&lt;T> Default { [Intrinsic] get; } = (EqualityComparer&lt;T>)ComparerHelpers.CreateDefaultEqualityComparer(typeof(T)); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0433\u043b\u0430\u0441\u0438\u0442, \u0447\u0442\u043e \u0441 \u0446\u0435\u043b\u044c\u044e \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0445 \u0440\u0430\u0441\u0445\u043e\u0434\u043e\u0432 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043a\u043e\u0434 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u044e\u0442 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0437\u0430 \u0441\u0447\u0435\u0442 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 \u0435\u0433\u043e \u043b\u043e\u0433\u0438\u043a\u0438 \u0432 \u043d\u0435\u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e ComparerHelpers).<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0436\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/coreclr\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/ComparerHelpers.cs#L116\" rel=\"noopener noreferrer nofollow\">\u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/a>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/38d\/9d0\/8e3\/38d9d08e3f68c5d2fb4d22aecb570241.png\" width=\"624\" height=\"462\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/38d\/9d0\/8e3\/38d9d08e3f68c5d2fb4d22aecb570241.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>internal static object CreateDefaultEqualityComparer(Type type) {             Debug.Assert(type != null &amp;&amp; type is RuntimeType);              object? result = null;             var runtimeType = (RuntimeType)type;              if (type == typeof(byte))             {                 \/\/ Specialize for byte so Array.IndexOf is faster.                 result = new ByteEqualityComparer();             }             else if (type == typeof(string))             {                 \/\/ Specialize for string, as EqualityComparer&lt;string>.Default is on the startup path                 result = new GenericEqualityComparer&lt;string>();             }             else if (type.IsAssignableTo(typeof(IEquatable&lt;>).MakeGenericType(type)))             {                 \/\/ If T implements IEquatable&lt;T> return a GenericEqualityComparer&lt;T>                 result = CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericEqualityComparer&lt;string>), runtimeType);             }             else if (type.IsGenericType)             {                 \/\/ Nullable does not implement IEquatable&lt;T?> directly because that would add an extra interface call per comparison.                 \/\/ Instead, it relies on EqualityComparer&lt;T?>.Default to specialize for nullables and do the lifted comparisons if T implements IEquatable.                 if (type.GetGenericTypeDefinition() == typeof(Nullable&lt;>))                 {                     result = TryCreateNullableEqualityComparer(runtimeType);                 }             }             else if (type.IsEnum)             {                 \/\/ The equality comparer for enums is specialized to avoid boxing.                 result = TryCreateEnumEqualityComparer(runtimeType);             }              return result ?? CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(ObjectEqualityComparer&lt;object>), runtimeType); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0439\u0434\u0435\u043c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443: <\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0415\u0441\u043b\u0438 \u0442\u0438\u043f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 byte, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 (ByteEqualityComparer) <\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f GenericEqualityComparer&lt;string>();<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0415\u0441\u043b\u0438 \u0442\u0438\u043f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 IEquatable, \u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 GenericEqualityComparer&lt;string> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f GenericEqualityComparer \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 (\u0434\u0430\u0436\u0435 \u043d\u0435 \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0439\u0442\u0435);<\/p>\n<p>4.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0415\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c (\u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c) \u0438 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0442 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f Nullable&lt;>, \u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/coreclr\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/ComparerHelpers.cs#L160\" rel=\"noopener noreferrer nofollow\">\u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435<\/a> NullableEqualityComparer&lt;int> \u00a0\u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f NullableEqualityComparer \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430;<\/p>\n<p>5.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0415\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u2013 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/coreclr\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/ComparerHelpers.cs#L179\" rel=\"noopener noreferrer nofollow\">\u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435<\/a> EnumEqualityComparer&lt;> \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f EnumEqualityComparer;<\/p>\n<p>6.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0412\u043e \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 ObjectEqualityComparer&lt;object> \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f ObjectEqualityComparer.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435\u0445\u0438\u0442\u0440\u043e\u0433\u043e \u043a\u043e\u0434\u0430 (\u0445\u043e\u0442\u0435\u043b \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 string builder, \u043d\u043e, \u0434\u0443\u043c\u0430\u044e, \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u0438\u0442\u044c :D) \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0436\u0435 \u0438\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u2013 \u043d\u0430\u0448:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ee6\/e26\/405\/ee6e26405a2db802b56dff3f78ab4ef5.png\" width=\"624\" height=\"66\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ee6\/e26\/405\/ee6e26405a2db802b56dff3f78ab4ef5.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">var documentsDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); FileInfo[] result1 = documentsDir.GetFiles(); FileInfo[] result2 = documentsDir.GetFiles();  Type type = result1[0].GetType(); Console.Write(     $\"type == typeof(byte): {type == typeof(byte)}\\n\" +     $\"type == typeof(string): {type == typeof(string)}\\n\" +     $\"type.IsAssignableTo(typeof(IEquatable&lt;>).MakeGenericType(type)): {type.IsAssignableTo(typeof(IEquatable&lt;>).MakeGenericType(type))}\\n\" +     $\"type.IsGenericType: {type.IsGenericType}\\n\" +     $\"type.IsEnum: {type.IsEnum}\\n\\n\");<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0427\u0442\u043e \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u043e \u043e\u0436\u0438\u0434\u0430\u0442\u044c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6b9\/4ef\/8af\/6b94ef8af42b1443848751a1555f43af.png\" width=\"593\" height=\"87\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6b9\/4ef\/8af\/6b94ef8af42b1443848751a1555f43af.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u00a0\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043f\u0443\u0442\u044c \u043b\u0435\u0436\u0438\u0442 \u0432 <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/libraries\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/EqualityComparer.cs\" rel=\"noopener noreferrer nofollow\">ObjectEqualityComparer<\/a>. \u0412\u043e\u0442, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438 \u043e\u043d:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6d1\/6cb\/eb0\/6d16cbeb0bda1a4100f0799f6b31837e.png\" width=\"624\" height=\"474\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6d1\/6cb\/eb0\/6d16cbeb0bda1a4100f0799f6b31837e.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public sealed partial class ObjectEqualityComparer&lt;T> : EqualityComparer&lt;T> {         [MethodImpl(MethodImplOptions.AggressiveInlining)]         public override bool Equals(T? x, T? y)         {             if (x != null)             {                 if (y != null) return x.Equals(y);                 return false;             }             if (y != null) return false;             return true;         }          [MethodImpl(MethodImplOptions.AggressiveInlining)]         public override int GetHashCode([DisallowNull] T obj) => obj?.GetHashCode() ?? 0;          \/\/ Equals method for the comparer itself.         public override bool Equals([NotNullWhen(true)] object? obj) =>             obj != null &amp;&amp; GetType() == obj.GetType();          public override int GetHashCode() =>             GetType().GetHashCode(); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>ObjectEqualityComparer \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 Equals \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u041e\u0431\u044a\u0435\u043a\u0442\u044b \u0440\u0430\u0432\u043d\u044b, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043e\u0431\u0430 null (\u0447\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e);<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u041e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0435 \u0440\u0430\u0432\u043d\u044b, \u0435\u0441\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 null;<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0415\u0441\u043b\u0438 \u043e\u0431\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0435 null, \u0442\u043e \u0438\u0445 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c Equals \u00ab\u043b\u0435\u0432\u043e\u0433\u043e\u00bb \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a <a href=\"https:\/\/docs.microsoft.com\/ru-ru\/dotnet\/api\/system.io.fileinfo?view=net-6.0#methods\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 FileInfo \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 Equals \u0441 \u043f\u043e\u043c\u0435\u0442\u043a\u043e\u0439 \u00ab\u0423\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043e \u043e\u0442 Object\u00bb. \u0427\u0442\u043e \u0436\u0435, <a href=\"https:\/\/docs.microsoft.com\/ru-ru\/dotnet\/api\/system.object.equals?view=net-6.0#System_Object_Equals_System_Object_\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0434\u0430<\/a> \u0438 \u043b\u0435\u0436\u0438\u0442 \u043d\u0430\u0448 \u043f\u0443\u0442\u044c! \u0422\u0430\u043c \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 \u00ab\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438\u00bb \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e:<\/p>\n<blockquote>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c, Equals(Object) \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0441\u0441\u044b\u043b\u043e\u043a, \u0430 \u0432\u044b\u0437\u043e\u0432 Equals(Object) \u043c\u0435\u0442\u043e\u0434\u0430 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d \u0432\u044b\u0437\u043e\u0432\u0443 ReferenceEquals \u043c\u0435\u0442\u043e\u0434\u0430. \u0420\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u0441\u0441\u044b\u043b\u043e\u043a \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<\/blockquote>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c, \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043d\u0430\u0448\u0435 \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u0435, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0435\u043c, \u043a\u0430\u043a \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c Except \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0442\u044c \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0441 \u043c\u043e\u0438\u043c\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<p>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0438\u0437 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u00ab\u043f\u043e\u043a\u0430 \u0442\u0430\u043a, \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0444\u0438\u043a\u0448\u0443\u00bb:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c8c\/e74\/707\/c8ce74707b8afe685bbee4e23606d0b5.png\" alt=\"\" title=\"\" width=\"571\" height=\"127\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c8c\/e74\/707\/c8ce74707b8afe685bbee4e23606d0b5.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">var documentsDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); FileInfo[] result1 = documentsDir.GetFiles(); FileInfo[] result2 = documentsDir.GetFiles(); foreach (FileInfo item in result1                                  .Select(i => i.FullName)                                  .Except(result2.Select(i => i.FullName))                                  .Select(i => new FileInfo(i))) {     Console.WriteLine(item.Name); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041c\u044b, \u043f\u043e \u0441\u0443\u0442\u0438, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c Except \u0434\u043b\u044f \u0434\u0432\u0443\u0445 IEnumerate&lt;string>, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0441\u043d\u043e\u0432\u0430 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c IEnumerate&lt;FileInfo>.  <\/p>\n<p>\u0412 \u0441\u0432\u0435\u0436\u0435\u043c .net6 \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.linq.enumerable.exceptby?view=net-6.0\" rel=\"noopener noreferrer nofollow\">ExceptBy<\/a>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/09b\/a5a\/b6c\/09ba5ab6c894ec3bcfd9face1504e746.png\" width=\"624\" height=\"59\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/09b\/a5a\/b6c\/09ba5ab6c894ec3bcfd9face1504e746.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">var documentsDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); FileInfo[] result1 = documentsDir.GetFiles(); FileInfo[] result2 = documentsDir.GetFiles(); foreach (FileInfo item in result1.ExceptBy(result2.Select(i => i.FullName), ks => ks.FullName)) {     Console.WriteLine(item.Name); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0443\u0436\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u044f\u0442\u043d\u0435\u0435 \u0438 \u0434\u0430\u0436\u0435 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0441 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0438 \u0441\u043d\u043e\u0432\u0430 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0438\u043d\u0430\u0447\u0435.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0434\u0435\u0435\u0439, \u043f\u043e\u0441\u0435\u0442\u0438\u0432\u0448\u0435\u0439 \u043c\u043e\u044e \u0433\u043e\u043b\u043e\u0432\u0443, \u0431\u044b\u043b\u043e \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c FileInfo \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c Equals, \u043d\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, FileInfo \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043d\u044b\u043c (sealed) \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u0430 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d, \u0442\u0430\u043a \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043f\u0443\u0442\u044c \u043d\u0430\u043c \u043e\u0442\u0440\u0435\u0437\u0430\u043d.<\/p>\n<p>\u041f\u043e\u0434\u043e\u0439\u0434\u0435\u043c \u043a \u0432\u043e\u043f\u0440\u043e\u0441\u0443 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b. \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e Equals \u0438\u043c\u0435\u0435\u0442 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0443, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0443\u044e \u0432\u0442\u043e\u0440\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c IEqualityComparer, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f: <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/596\/73c\/059\/59673c05918007a785169dc6b0a30b8c.png\" width=\"624\" height=\"216\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/596\/73c\/059\/59673c05918007a785169dc6b0a30b8c.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary><\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">var documentsDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); FileInfo[] result1 = documentsDir.GetFiles(); FileInfo[] result2 = documentsDir.GetFiles();  foreach (FileInfo item in result1.Except(result2, new CustomFileInfoComparer())) {     Console.WriteLine(item.Name); }  public class CustomFileInfoComparer : IEqualityComparer&lt;FileInfo> {     bool IEqualityComparer&lt;FileInfo>.Equals(FileInfo? lhv, FileInfo? rhv)        => lhv?.FullName == rhv?.FullName;     int IEqualityComparer&lt;FileInfo>.GetHashCode(FileInfo obj) => obj.FullName.GetHashCode(); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u042d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e \u043a\u043e\u0434\u0443 \u0432\u0430\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u0438\u0442 \u0435\u0449\u0435 \u0445\u043e\u0442\u044f \u0431\u044b \u0440\u0430\u0437 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c IEnumerable&lt;FileInfo>.  <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0443 \u043c\u0435\u043d\u044f \u0432\u0441\u0435, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0448\u0435\u043b \u043b\u044e\u0431\u043e\u043f\u044b\u0442\u043d\u044b\u043c \u043c\u043e\u0439 \u0441\u043a\u0440\u043e\u043c\u043d\u044b\u0439 \u0442\u0440\u0443\u0434.<\/p>\n<p>\u0425\u043e\u0447\u0435\u0442\u0441\u044f \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u0443\u044e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0435\u0439 \u0436\u0435\u043d\u0435 \u0437\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u0432 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0443 <a href=\"https:\/\/t.me\/dotnettalks\" rel=\"noopener noreferrer nofollow\">.NET Talks?<\/a><\/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\/590445\/\"> https:\/\/habr.com\/ru\/articles\/590445\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043a\u043e\u0434\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u00ab\u043d\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u0442\u044b \u043e\u0442 \u043d\u0435\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0448\u044c\u00bb. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0438 \u043f\u043e\u0434\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u043e \u043c\u0435\u043d\u044f \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u043f\u044b\u0442\u0430\u044e\u0441\u044c \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 Except \u0432 Linq \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u0430\u043a, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d, \u0430 \u043d\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u044f \u0445\u043e\u0447\u0443.<\/p>\n<hr\/>\n<p>\u0427\u0442\u043e, \u043f\u043e \u0432\u0430\u0448\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e, \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cs\">var documentsDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));  FileInfo[] FirstDirrectoryFiles = documentsDir.GetFiles();  FileInfo[] SecondDirrectoryFiles = documentsDir.GetFiles();  foreach (FileInfo item in FirstDirrectoryFiles.Except(SecondDirrectoryFiles))  {  Console.WriteLine(item.Name);  }<\/code><\/pre>\n<p>\u042f \u0432\u043e\u0442 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043b, \u0447\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e Except \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0447\u0438\u0442\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e (IEnumerable) \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 (IEnumerable) \u043b\u0435\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432\u043e\u043f\u0440\u0435\u043a\u0438 \u043c\u043e\u0438\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f\u043c \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043d\u0435 \u0432\u0441\u044f\u043a\u043e\u0433\u043e \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u043d\u0435 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f (\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 .NET 5 \u0438 \u0432 .NET 6 \u2014 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u0435\u043d). \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0438 \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <a href=\"https:\/\/docs.microsoft.com\/ru-ru\/dotnet\/api\/system.linq.enumerable.except?view=net-6.0\" rel=\"noopener noreferrer nofollow\">Except<\/a>. \u0422\u0430\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u00ab\u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438\u00bb \u0438 \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0438:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Except&lt;TSource>(IEnumerable&lt;TSource>,   IEnumerable&lt;TSource>)<\/p>\n<\/td>\n<td>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u0442   \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043b\u044f   \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Except&lt;TSource>(IEnumerable&lt;TSource>,   IEnumerable&lt;TSource>, IEqualityComparer&lt;TSource>)<\/p>\n<\/td>\n<td>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u0442   \u0440\u0430\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043b\u044f   \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 IEqualityComparer&lt;T>.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0430\u0448 \u043a\u043e\u0434 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a, \u043a\u0430\u043a \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b, \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/dotnet\/runtime\/\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/dotnet\/runtime\/<\/a> \u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043c\u0435\u0442\u043e\u0434\u0430 Except.<\/p>\n<p>\u041d\u0430\u0448\u0430 <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/a7c69745a4e22757c69f65d2a750e2d6923e1186\/src\/libraries\/System.Linq\/src\/System\/Linq\/Except.cs#L10\" rel=\"noopener noreferrer nofollow\">\u0442\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430<\/a>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public static IEnumerable&lt;TSource> Except&lt;TSource>(this IEnumerable&lt;TSource> first, IEnumerable&lt;TSource> second) {             if (first == null)             {                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);             }              if (second == null)             {                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);             }              return ExceptIterator(first, second, null); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u044b\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0432 <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/a7c69745a4e22757c69f65d2a750e2d6923e1186\/src\/libraries\/System.Linq\/src\/System\/Linq\/Except.cs#L79\" rel=\"noopener noreferrer nofollow\">ExceptIterator<\/a>.<\/p>\n<p>\u0421\u0442\u0440\u043e\u0433\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u043c\u0435\u0442\u043e\u0434 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0442\u0430\u043a\u0436\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public static IEnumerable&lt;TSource> Except&lt;TSource>(this IEnumerable&lt;TSource> first, IEnumerable&lt;TSource> second, IEqualityComparer&lt;TSource>? comparer) {             if (first == null)             {                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.first);             }              if (second == null)             {                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second);             }              return ExceptIterator(first, second, comparer); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430, \u0430 \u043d\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e? \u0421\u0438\u043b\u0430\u043c\u0438 <a href=\"https:\/\/t.me\/dotnettalks\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430<\/a> \u0431\u044b\u043b\u043e \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0434\u0435\u043b\u043e \u0432 <a href=\"https:\/\/coding.abel.nu\/2014\/07\/adding-an-overload-is-a-breaking-change\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u043c<\/a> \u0438 <a href=\"https:\/\/rules.sonarsource.com\/csharp\/RSPEC-2360\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u043c<\/a>.<\/p>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a\u043e\u0434 <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/a7c69745a4e22757c69f65d2a750e2d6923e1186\/src\/libraries\/System.Linq\/src\/System\/Linq\/Except.cs#L79\" rel=\"noopener noreferrer nofollow\">ExceptIterator<\/a>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">private static IEnumerable&lt;TSource> ExceptIterator&lt;TSource>(IEnumerable&lt;TSource> first, IEnumerable&lt;TSource> second, IEqualityComparer&lt;TSource>? comparer) {             var set = new HashSet&lt;TSource>(second, comparer);              foreach (TSource element in first)             {                 if (set.Add(element))                 {                     yield return element;                 }             } }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0418\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/libraries\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/HashSet.cs#L55\" rel=\"noopener noreferrer nofollow\">\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/a>. \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430.<\/p>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430: \u00a0<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 \u0440\u0430\u0432\u0435\u043d null, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e Default \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 EqualityComparer.  <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public HashSet(IEqualityComparer&lt;T>? comparer) {             if (comparer is not null &amp;&amp; comparer != EqualityComparer&lt;T>.Default) \/\/ first check for null to avoid forcing default comparer instantiation unnecessarily             {                 _comparer = comparer;             }              \/\/ Special-case EqualityComparer&lt;string>.Default, StringComparer.Ordinal, and StringComparer.OrdinalIgnoreCase.             \/\/ We use a non-randomized comparer for improved perf, falling back to a randomized comparer if the             \/\/ hash buckets become unbalanced.             if (typeof(T) == typeof(string))             {                 IEqualityComparer&lt;string>? stringComparer = NonRandomizedStringEqualityComparer.GetStringComparer(_comparer);                 if (stringComparer is not null)                 {                     _comparer = (IEqualityComparer&lt;T>?)stringComparer;                 }             } }<\/code><\/pre>\n<\/div>\n<\/details>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/coreclr\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/EqualityComparer.CoreCLR.cs#L10\" rel=\"noopener noreferrer nofollow\">\u0422\u0443\u0442<\/a>, \u043d\u0430 \u043c\u043e\u0439 \u0441\u043a\u0440\u043e\u043c\u043d\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0432\u0441\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e:  <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public abstract partial class EqualityComparer&lt;T> : IEqualityComparer, IEqualityComparer&lt;T> {         \/\/ To minimize generic instantiation overhead of creating the comparer per type, we keep the generic portion of the code as small         \/\/ as possible and define most of the creation logic in a non-generic class.         public static EqualityComparer&lt;T> Default { [Intrinsic] get; } = (EqualityComparer&lt;T>)ComparerHelpers.CreateDefaultEqualityComparer(typeof(T)); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0433\u043b\u0430\u0441\u0438\u0442, \u0447\u0442\u043e \u0441 \u0446\u0435\u043b\u044c\u044e \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0445 \u0440\u0430\u0441\u0445\u043e\u0434\u043e\u0432 \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043a\u043e\u0434 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u044e\u0442 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0437\u0430 \u0441\u0447\u0435\u0442 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 \u0435\u0433\u043e \u043b\u043e\u0433\u0438\u043a\u0438 \u0432 \u043d\u0435\u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e ComparerHelpers).<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0436\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/coreclr\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/ComparerHelpers.cs#L116\" rel=\"noopener noreferrer nofollow\">\u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/a>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>internal static object CreateDefaultEqualityComparer(Type type) {             Debug.Assert(type != null &amp;&amp; type is RuntimeType);              object? result = null;             var runtimeType = (RuntimeType)type;              if (type == typeof(byte))             {                 \/\/ Specialize for byte so Array.IndexOf is faster.                 result = new ByteEqualityComparer();             }             else if (type == typeof(string))             {                 \/\/ Specialize for string, as EqualityComparer&lt;string>.Default is on the startup path                 result = new GenericEqualityComparer&lt;string>();             }             else if (type.IsAssignableTo(typeof(IEquatable&lt;>).MakeGenericType(type)))             {                 \/\/ If T implements IEquatable&lt;T> return a GenericEqualityComparer&lt;T>                 result = CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericEqualityComparer&lt;string>), runtimeType);             }             else if (type.IsGenericType)             {                 \/\/ Nullable does not implement IEquatable&lt;T?> directly because that would add an extra interface call per comparison.                 \/\/ Instead, it relies on EqualityComparer&lt;T?>.Default to specialize for nullables and do the lifted comparisons if T implements IEquatable.                 if (type.GetGenericTypeDefinition() == typeof(Nullable&lt;>))                 {                     result = TryCreateNullableEqualityComparer(runtimeType);                 }             }             else if (type.IsEnum)             {                 \/\/ The equality comparer for enums is specialized to avoid boxing.                 result = TryCreateEnumEqualityComparer(runtimeType);             }              return result ?? CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(ObjectEqualityComparer&lt;object>), runtimeType); }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0439\u0434\u0435\u043c \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443: <\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0415\u0441\u043b\u0438 \u0442\u0438\u043f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 byte, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0430\u0440\u0430\u0442\u043e\u0440 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 (ByteEqualityComparer) <\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f GenericEqualityComparer&lt;string>();<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0415\u0441\u043b\u0438 \u0442\u0438\u043f \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 IEquatable, \u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 GenericEqualityComparer&lt;string> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f GenericEqualityComparer \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 (\u0434\u0430\u0436\u0435 \u043d\u0435 \u0441\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0439\u0442\u0435);<\/p>\n<p>4.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0415\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c (\u043e\u0431\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c) \u0438 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0442 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f Nullable&lt;>, \u00a0<a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/coreclr\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/ComparerHelpers.cs#L160\" rel=\"noopener noreferrer nofollow\">\u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435<\/a> NullableEqualityComparer&lt;int> \u00a0\u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f NullableEqualityComparer \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430;<\/p>\n<p>5.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0415\u0441\u043b\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u2013 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435, <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/coreclr\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/ComparerHelpers.cs#L179\" rel=\"noopener noreferrer nofollow\">\u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435<\/a> EnumEqualityComparer&lt;> \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f EnumEqualityComparer;<\/p>\n<p>6.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u0412\u043e \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 ObjectEqualityComparer&lt;object> \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f ObjectEqualityComparer.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435\u0445\u0438\u0442\u0440\u043e\u0433\u043e \u043a\u043e\u0434\u0430 (\u0445\u043e\u0442\u0435\u043b \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 string builder, \u043d\u043e, \u0434\u0443\u043c\u0430\u044e, \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0431\u0438\u0442\u044c :D) \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0436\u0435 \u0438\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u2013 \u043d\u0430\u0448:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">var documentsDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); FileInfo[] result1 = documentsDir.GetFiles(); FileInfo[] result2 = documentsDir.GetFiles();  Type type = result1[0].GetType(); Console.Write(     $\"type == typeof(byte): {type == typeof(byte)}\\n\" +     $\"type == typeof(string): {type == typeof(string)}\\n\" +     $\"type.IsAssignableTo(typeof(IEquatable&lt;>).MakeGenericType(type)): {type.IsAssignableTo(typeof(IEquatable&lt;>).MakeGenericType(type))}\\n\" +     $\"type.IsGenericType: {type.IsGenericType}\\n\" +     $\"type.IsEnum: {type.IsEnum}\\n\\n\");<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0427\u0442\u043e \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u043e \u043e\u0436\u0438\u0434\u0430\u0442\u044c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u00a0\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043f\u0443\u0442\u044c \u043b\u0435\u0436\u0438\u0442 \u0432 <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657\/src\/libraries\/System.Private.CoreLib\/src\/System\/Collections\/Generic\/EqualityComparer.cs\" rel=\"noopener noreferrer nofollow\">ObjectEqualityComparer<\/a>. \u0412\u043e\u0442, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438 \u043e\u043d:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041a\u043e\u0434 \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public sealed partial class ObjectEqualityComparer&lt;T> : EqualityComparer&lt;T> {         [MethodImpl(MethodImplOptions.AggressiveInlining)]         public override bool Equals(T? x, T? y)         {             if (x != null)             {                 if (y != null) return x.Equals(y);                 return false;             }             if (y != null) return false;  <\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-415763","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/415763","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=415763"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/415763\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=415763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=415763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=415763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}