{"id":343005,"date":"2022-12-22T15:00:50","date_gmt":"2022-12-22T15:00:50","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343005"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343005","title":{"rendered":"<span>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b unsafe \u043a\u043e\u0434\u0430 C#<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/134\/473\/6ec\/1344736ecce3f97da043c845a1e5a5c3.png\" width=\"1920\" height=\"1080\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/134\/473\/6ec\/1344736ecce3f97da043c845a1e5a5c3.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c unsafe \u043a\u043e\u0434 \u0438 \u043f\u0430\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b, readonly \u043f\u043e\u043b\u044f \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0431\u0435\u0437 set \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>\u042f \u043d\u0435 \u0437\u043d\u0430\u044e \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f, \u043d\u043e \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0438 \u043a\u043e\u0434\u0430 \u0432 \u043d\u0435\u0439 \u043f\u0440\u043e\u0441\u0442\u043e <u>\u0432\u0437\u0440\u044b\u0432\u0430\u044e\u0442 \u043c\u043d\u0435 \u043c\u043e\u0437\u0433,<\/u> \u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f.<\/p>\n<h3>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 1<\/h3>\n<p>\u041a\u0430\u043a \u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u0447\u0442\u043e \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0447\u0435\u043c \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435?<\/p>\n<pre><code class=\"cs\">string str = \"Strings are immutable!\";  for(int i = 0; i &lt; str.Length \/ 2; i++) {     fixed(char* strPtr = str)     {         char tmp = strPtr[i];         strPtr[i] = str[str.Length - i - 1];         strPtr[str.Length - i - 1] = tmp;     } }  Console.WriteLine(\"Strings are immutable!\"); \/\/ \u041e\u0442\u0432\u0435\u0442 \u0432\u0430\u0441 \u0443\u0434\u0438\u0432\u0438\u0442<\/code><\/pre>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0447\u0442\u043e \u0437\u0430 \u0433\u043b\u0443\u043f\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441, \u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u044f \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u044f \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u0438\u0432\u0438\u043b\u0441\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u0427\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043a\u043e\u0434:<\/summary>\n<div class=\"spoiler__content\">\n<blockquote>\n<p>!elbatummi era sgnirtS<\/p>\n<\/blockquote>\n<p>\u0414\u0430, \u0434\u0430, \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u0441\u0430\u043c\u0438.<\/p>\n<\/div>\n<\/details>\n<p>\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 \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c 3 \u0432\u0435\u0449\u0438:<\/p>\n<ul>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<li>\n<p>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e<\/p>\n<\/li>\n<li>\n<p>\u0421\u0442\u0440\u043e\u043a\u0430 &#8212; \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0441\u0442! \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043e\u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0421\u0442\u0440\u043e\u043a\u0430 \u044d\u0442\u043e \u0430\u0434\u0440\u0435\u0441 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b, \u043d\u0435 \u0441\u0430\u043c \u0441\u0438\u043c\u0432\u043e\u043b, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0430\u0434\u0440\u0435\u0441! \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043c\u0435\u043d\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043f\u043e \u044f\u0447\u0435\u0439\u043a\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0438\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0432\u044b\u0432\u0435\u0441\u0442\u0438 &#171;Strings are immutable!&#187;, \u043e\u0431\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0443\u0436\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bc3\/a51\/06c\/bc3a5106c87890b11d3eeef5e4d0eec2.png\" alt=\"ILDasm.exe | \u041c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443\" title=\"ILDasm.exe | \u041c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443\" width=\"623\" height=\"392\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bc3\/a51\/06c\/bc3a5106c87890b11d3eeef5e4d0eec2.png\"\/><figcaption>ILDasm.exe | \u041c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443<\/figcaption><\/figure>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0442\u0443\u0442 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442 \u0441\u0442\u0440\u043e\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432 <strong>\u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435<\/strong>, \u0442\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c, \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u0442\u0440\u043e\u043a\u0435 &#171;Strings are immutable!&#187; \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0441\u0430\u043c\u0438 \u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u044f. \u042f \u043d\u0435 \u0437\u043d\u0430\u044e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439, \u043d\u043e \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u0431\u0443\u0434\u0435\u0442, \u043c\u044f\u0433\u043a\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u0441\u043b\u043e\u0436\u043d\u043e.<\/p>\n<p>\u0410 \u0432\u0435\u0434\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 \u043d\u0430\u0441 \u0434\u0430\u0436\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434! \u0421\u0435\u0440\u044c\u0435\u0437\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434, \u043d\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435, \u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0441\u044f. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<h3>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 2<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043a\u0430\u043a \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0443. \u042f \u043d\u0430\u0437\u0432\u0430\u043b \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 LibReverse \u0438 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 \u043d\u0435\u043c LibReverseString. \u042f \u0432\u043a\u043b\u044e\u0447\u0438\u043b \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438 \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 Reverse, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043f\u0438\u0435\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 <strong>\u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430 1.<\/strong><\/p>\n<pre><code class=\"cs\">public class LibReverseString {     unsafe public static void Reverse(string str)     {         fixed (char* strPtr = str)         {             for (int i = 0; i &lt; str.Length \/ 2; i++)             {                 char tmp = strPtr[i];                 strPtr[i] = strPtr[str.Length - i - 1];                 strPtr[str.Length - i - 1] = tmp;             }         }     } }<\/code><\/pre>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 Program.cs (\u0433\u0434\u0435 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 Main) \u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u043d\u0430\u0448\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443<\/p>\n<pre><code class=\"cs\">using LibReverse;<\/code><\/pre>\n<p>\u0418 \u0441\u0434\u0435\u043b\u0430\u043b \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 Reverse<\/p>\n<pre><code class=\"cs\">static void Main(string[] args) {     string str = \"Strings are immutable!\";      LibReverseString.Reverse(str);      Console.WriteLine(\"Strings are immutable!\"); }  \/\/ Output: \/\/ !elbatummi era sgnirtS<\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c Main \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u0430\u0436\u0435 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d.<\/p>\n<h3>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3. \u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445<\/h3>\n<p>\u0412\u0435\u0437\u0434\u0435 \u0432 <strong>\u041b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 3<\/strong> \u0432\u044b\u0437\u043e\u0432 <code>LibReverseString.Reverse(str)<\/code> \u043c\u043e\u0436\u043d\u043e \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f:<\/p>\n<pre><code class=\"cs\">fixed (char* strPtr = str) {     for (int i = 0; i &lt; str.Length \/ 2; i++)     {         char tmp = strPtr[i];         strPtr[i] = strPtr[str.Length - i - 1];         strPtr[str.Length - i - 1] = tmp;     } }<\/code><\/pre>\n<p>\u042f \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0432\u044b\u0437\u043e\u0432 Reverse \u0438\u0437 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0414\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0443\u0442 \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0441\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u044f \u0432\u044b\u0441\u043a\u0430\u0436\u0443 \u0432 \u043a\u043e\u043d\u0446\u0435.<\/p>\n<p>\u042f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 Foo, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d.<\/p>\n<pre><code class=\"cs\">private static void Foo() {     string str = \"Strings are immutable!\";     Console.WriteLine(str); }<\/code><\/pre>\n<p><strong>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3.1:<\/strong> \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u0435\u0442\u043e\u0434 Main \u0438\u043c\u0435\u0435\u0442 \u0443 \u043d\u0430\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0438\u0434<\/p>\n<pre><code class=\"cs\">unsafe static void Main(string[] args) {     string str = \"Strings are immutable!\";          Foo();          LibReverseString.Reverse(str);      Foo(); }  \/\/ Output: \/\/ Strings are immutable! \/\/ !elbatummi era sgnirtS<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0438\u0434\u043d\u043e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430, \u043d\u043e \u0435\u0441\u043b\u0438 \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043e\u0434, \u0443\u0431\u0440\u0430\u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 Foo.<\/p>\n<p><strong>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3.2: <\/strong>\u043d\u0435\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 Foo<\/p>\n<pre><code class=\"cs\">unsafe static void Main(string[] args) {     string str = \"Strings are immutable!\";          LibReverseString.Reverse(str);          Foo(); }  \/\/ Output: \/\/ Strings are immutable!<\/code><\/pre>\n<p>\u041c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0431\u0440\u0430\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 Foo \u0435\u0449\u0435 \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 Reverse, \u043d\u043e Reverse \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b. \u0418\u043b\u0438 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b? \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0442\u0435\u043e\u0440\u0438\u044f \u043d\u0430\u0441\u0447\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d, \u043f\u0440\u043e\u0448\u0443 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u0442\u043e\u0447\u043d\u043e.<\/p>\n<p>\u0412 <strong>\u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 3.1, <\/strong>\u0432\u044b\u0437\u044b\u0432\u0430\u044f Foo \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437, \u043c\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c JIT-\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043b\u044f Foo \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e str \u0441 \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 &#171;Strings are immutable!&#187;, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u043c\u044b \u0435\u0435 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c.<\/p>\n<p>\u0412 <strong>\u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 3.2<\/strong> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Foo \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0443. \u041b\u043e\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u044f Foo \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f str \u043d\u0435 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u0443\u044e \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443. \u0412 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u044d\u0442\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438 \u043c\u043e\u0433\u0443 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 <strong>\u043b\u0438\u0441\u0442\u0438\u043d\u0433 3.3<\/strong>.<\/p>\n<p><strong>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3.3<\/strong>: \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e JIT \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u0432\u0441\u0435\u0439 \u0441\u0431\u043e\u0440\u043a\u0438 TestApp.<\/p>\n<pre><code class=\"cs\">unsafe static void Main(string[] args) {     \/\/ Pre-JIT-compilation     foreach (var type in Assembly.Load(\"TestApp\").GetTypes())     {         foreach (var method in type.GetMethods(BindingFlags.DeclaredOnly |                             BindingFlags.NonPublic |                             BindingFlags.Public | BindingFlags.Instance |                             BindingFlags.Static))         {             System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod(method.MethodHandle);         }     }      string str = \"Strings are immutable!\";      LibReverseString.Reverse(str);      Foo(); }  \/\/ Output: \/\/ !elbatummi era sgnirtS<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u044f \u0432\u0437\u044f\u043b \u0443 <a href=\"https:\/\/www.codeproject.com\/script\/Membership\/View.aspx?mid=3643879\" rel=\"noopener noreferrer nofollow\">Vitaliy Liptchinsky<\/a> \u0438\u0437 \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e JIT-\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e (<a href=\"https:\/\/www.codeproject.com\/Articles\/31316\/Pre-compile-pre-JIT-your-assembly-on-the-fly-or-tr\" rel=\"noopener noreferrer nofollow\">https:\/\/www.codeproject.com\/Articles\/31316\/Pre-compile-pre-JIT-your-assembly-on-the-fly-or-tr<\/a>)<\/p>\n<h3>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 4<\/h3>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u044d\u0442\u043e \u043d\u0435\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e\u0431 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c.<\/p>\n<pre><code class=\"cs\">class Program {     public const string PI = \"3.14\";          unsafe static void Main(string[] args)     {         fixed (char* PIPtr = PI)         {             PIPtr[0] = '0';         }         Console.WriteLine(PI); \/\/ 0.14     }  }<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442, \u043d\u0430\u043f\u043e\u043c\u043d\u044e \u0432\u0430\u043c \u0435\u0449\u0435 \u0440\u0430\u0437, \u0441\u0442\u0440\u043e\u043a\u0430 &#8212; \u044d\u0442\u043e \u0410\u0414\u0420\u0415\u0421 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b. \u0418 \u0430\u0434\u0440\u0435\u0441 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0439. \u0425\u043e\u0442\u044f \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u044f \u0434\u0443\u043c\u0430\u044e, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0442\u043e\u0436\u0435.<\/p>\n<p>Visual Studio \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u043a &#171;3.14&#187;.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/27a\/f8a\/a9f\/27af8aa9fdabea846e55fbd843705bdf.png\" width=\"424\" height=\"127\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/27a\/f8a\/a9f\/27af8aa9fdabea846e55fbd843705bdf.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 4.1:<\/strong> \u0415\u0441\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 Foo \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c Main<\/p>\n<pre><code class=\"cs\">unsafe static void Main(string[] args) {      fixed (char* PIPtr = PI)     {         PIPtr[0] = '0';     }        Console.WriteLine(PI); \/\/ 0.14      Foo(); }  private static void Foo() {     Console.WriteLine(PI); \/\/ 3.14 }  \/\/ Output: \/\/ 0.14 \/\/ 3.14<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0442\u0430\u043a\u0430\u044f \u0436\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u044f, \u043a\u0430\u043a \u0432 <strong>\u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 3<\/strong>. \u0420\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u0442 \u043d\u0435 \u0431\u0443\u0434\u0443, \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e JIT-\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e, \u0442\u043e Foo \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e &#171;0.14&#187;.<\/p>\n<h3>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 5<\/h3>\n<p>\u0422\u0443\u0442 \u043c\u044b \u0432\u0438\u0434\u0438\u043c &#171;\u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0439&#187; \u043a\u043b\u0430\u0441\u0441. \u041c\u044b \u0436\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c Name, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u043c\u0435\u0435\u0442 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e readonly? \u041c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443, \u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e.<\/p>\n<pre><code class=\"cs\">public class ImmutablePerson {          public string Name { get; }      public ImmutablePerson(string name)     {         Name = name;     } }<\/code><\/pre>\n<pre><code class=\"cs\">ImmutablePerson person = new ImmutablePerson(\"William\");  Console.WriteLine(person.Name); \/\/ William  fixed (char* strPtr = person.Name) {     strPtr[0] = 'M';     strPtr[1] = 'i';     strPtr[2] = 'c';     strPtr[3] = 'h';     strPtr[4] = 'a';     strPtr[5] = 'e';     strPtr[6] = 'l'; }  Console.WriteLine(person.Name); \/\/ Michael<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e Name \u0441 init-\u0430\u043a\u0441\u0435\u0441\u0441\u043e\u0440\u043e\u043c \u0438\u043b\u0438 \u0432\u043e\u0432\u0441\u0435 readonly \u043f\u043e\u043b\u0435\u043c:<\/p>\n<pre><code class=\"cs\">public string Name { get; init; }<\/code><\/pre>\n<pre><code class=\"cs\">public readonly string Name;<\/code><\/pre>\n<h3>\u041f\u043e\u0441\u043b\u0435\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u043f\u0440\u043e\u0447\u0435\u043b \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0443\u0437\u043d\u0430\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0438\u043b\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e, \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u044f \u0445\u043e\u0442\u044c \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u0441\u043c\u043e\u0433 \u0432\u0430\u0441 \u0443\u0434\u0438\u0432\u0438\u0442\u044c.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 <strong>\u041a\u0441\u0435\u043d\u0438\u0438 \u041c\u043e\u0441\u0435\u0435\u043d\u043a\u043e\u0432\u043d\u044b<\/strong> (<a href=\"https:\/\/habr.com\/ru\/users\/kmoseenk\/\" rel=\"noopener noreferrer nofollow\">@kmoseenk<\/a>) \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043d\u043e \u043f\u0440\u043e \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a, \u0447\u0430\u0441\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432\u0437\u044f\u0442\u043e \u0438\u0437 \u043d\u0435\u0435 &#8212; <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/676680\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/company\/otus\/blog\/676680\/<\/a><\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u043d\u0438\u0439 \u043e\u0431 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 .NET \u044f \u0443\u0437\u043d\u0430\u043b \u0432 \u043a\u043d\u0438\u0433\u0435 &#8216;CLR via C#&#8217; \u043e\u0442 \u0430\u0432\u0442\u043e\u0440\u0430 \u0414\u0436\u0435\u0444\u0444\u0440\u0438 \u0420\u0438\u0445\u0442\u0435\u0440\u0430.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/707172\/\"> https:\/\/habr.com\/ru\/post\/707172\/<\/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<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c unsafe \u043a\u043e\u0434 \u0438 \u043f\u0430\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b, readonly \u043f\u043e\u043b\u044f \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0431\u0435\u0437 set \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>\u042f \u043d\u0435 \u0437\u043d\u0430\u044e \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f, \u043d\u043e \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0438 \u043a\u043e\u0434\u0430 \u0432 \u043d\u0435\u0439 \u043f\u0440\u043e\u0441\u0442\u043e <u>\u0432\u0437\u0440\u044b\u0432\u0430\u044e\u0442 \u043c\u043d\u0435 \u043c\u043e\u0437\u0433,<\/u> \u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f.<\/p>\n<h3>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 1<\/h3>\n<p>\u041a\u0430\u043a \u0434\u0443\u043c\u0430\u0435\u0442\u0435 \u0447\u0442\u043e \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0438 \u0447\u0435\u043c \u0432\u044b\u0437\u0432\u0430\u043d\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435?<\/p>\n<pre><code class=\"cs\">string str = \"Strings are immutable!\";  for(int i = 0; i &lt; str.Length \/ 2; i++) {     fixed(char* strPtr = str)     {         char tmp = strPtr[i];         strPtr[i] = str[str.Length - i - 1];         strPtr[str.Length - i - 1] = tmp;     } }  Console.WriteLine(\"Strings are immutable!\"); \/\/ \u041e\u0442\u0432\u0435\u0442 \u0432\u0430\u0441 \u0443\u0434\u0438\u0432\u0438\u0442<\/code><\/pre>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0447\u0442\u043e \u0437\u0430 \u0433\u043b\u0443\u043f\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441, \u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u044f \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u044f \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u0438\u0432\u0438\u043b\u0441\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u0427\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043a\u043e\u0434:<\/summary>\n<div class=\"spoiler__content\">\n<blockquote>\n<p>!elbatummi era sgnirtS<\/p>\n<\/blockquote>\n<p>\u0414\u0430, \u0434\u0430, \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u0441\u0430\u043c\u0438.<\/p>\n<\/div>\n<\/details>\n<p>\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 \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c 3 \u0432\u0435\u0449\u0438:<\/p>\n<ul>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a<\/p>\n<\/li>\n<li>\n<p>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e<\/p>\n<\/li>\n<li>\n<p>\u0421\u0442\u0440\u043e\u043a\u0430 &#8212; \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0441\u0442! \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043e\u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0421\u0442\u0440\u043e\u043a\u0430 \u044d\u0442\u043e \u0430\u0434\u0440\u0435\u0441 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b, \u043d\u0435 \u0441\u0430\u043c \u0441\u0438\u043c\u0432\u043e\u043b, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0430\u0434\u0440\u0435\u0441! \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043c\u0435\u043d\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043f\u043e \u044f\u0447\u0435\u0439\u043a\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0438\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0432\u044b\u0432\u0435\u0441\u0442\u0438 &#171;Strings are immutable!&#187;, \u043e\u0431\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0443\u0436\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<figure class=\"full-width\"><figcaption>ILDasm.exe | \u041c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443<\/figcaption><\/figure>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0442\u0443\u0442 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442 \u0441\u0442\u0440\u043e\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432 <strong>\u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435<\/strong>, \u0442\u043e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c, \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u0442\u0440\u043e\u043a\u0435 &#171;Strings are immutable!&#187; \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0441\u0430\u043c\u0438 \u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u044f. \u042f \u043d\u0435 \u0437\u043d\u0430\u044e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439, \u043d\u043e \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u0431\u0443\u0434\u0435\u0442, \u043c\u044f\u0433\u043a\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u0441\u043b\u043e\u0436\u043d\u043e.<\/p>\n<p>\u0410 \u0432\u0435\u0434\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443 \u043d\u0430\u0441 \u0434\u0430\u0436\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434! \u0421\u0435\u0440\u044c\u0435\u0437\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434, \u043d\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435, \u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0441\u044f. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<h3>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 2<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043a\u0430\u043a \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0443. \u042f \u043d\u0430\u0437\u0432\u0430\u043b \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 LibReverse \u0438 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432 \u043d\u0435\u043c LibReverseString. \u042f \u0432\u043a\u043b\u044e\u0447\u0438\u043b \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438 \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 Reverse, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043f\u0438\u0435\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 <strong>\u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430 1.<\/strong><\/p>\n<pre><code class=\"cs\">public class LibReverseString {     unsafe public static void Reverse(string str)     {         fixed (char* strPtr = str)         {             for (int i = 0; i &lt; str.Length \/ 2; i++)             {                 char tmp = strPtr[i];                 strPtr[i] = strPtr[str.Length - i - 1];                 strPtr[str.Length - i - 1] = tmp;             }         }     } }<\/code><\/pre>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 Program.cs (\u0433\u0434\u0435 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 Main) \u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u043d\u0430\u0448\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443<\/p>\n<pre><code class=\"cs\">using LibReverse;<\/code><\/pre>\n<p>\u0418 \u0441\u0434\u0435\u043b\u0430\u043b \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 Reverse<\/p>\n<pre><code class=\"cs\">static void Main(string[] args) {     string str = \"Strings are immutable!\";      LibReverseString.Reverse(str);      Console.WriteLine(\"Strings are immutable!\"); }  \/\/ Output: \/\/ !elbatummi era sgnirtS<\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c Main \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u0430\u0436\u0435 \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d.<\/p>\n<h3>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3. \u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445<\/h3>\n<p>\u0412\u0435\u0437\u0434\u0435 \u0432 <strong>\u041b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 3<\/strong> \u0432\u044b\u0437\u043e\u0432 <code>LibReverseString.Reverse(str)<\/code> \u043c\u043e\u0436\u043d\u043e \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f:<\/p>\n<pre><code class=\"cs\">fixed (char* strPtr = str) {     for (int i = 0; i &lt; str.Length \/ 2; i++)     {         char tmp = strPtr[i];         strPtr[i] = strPtr[str.Length - i - 1];         strPtr[str.Length - i - 1] = tmp;     } }<\/code><\/pre>\n<p>\u042f \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0432\u044b\u0437\u043e\u0432 Reverse \u0438\u0437 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<p>\u0414\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0443\u0442 \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0441\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u044f \u0432\u044b\u0441\u043a\u0430\u0436\u0443 \u0432 \u043a\u043e\u043d\u0446\u0435.<\/p>\n<p>\u042f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 Foo, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d.<\/p>\n<pre><code class=\"cs\">private static void Foo() {     string str = \"Strings are immutable!\";     Console.WriteLine(str); }<\/code><\/pre>\n<p><strong>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3.1:<\/strong> \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u0435\u0442\u043e\u0434 Main \u0438\u043c\u0435\u0435\u0442 \u0443 \u043d\u0430\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0438\u0434<\/p>\n<pre><code class=\"cs\">unsafe static void Main(string[] args) {     string str = \"Strings are immutable!\";          Foo();          LibReverseString.Reverse(str);      Foo(); }  \/\/ Output: \/\/ Strings are immutable! \/\/ !elbatummi era sgnirtS<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0438\u0434\u043d\u043e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430, \u043d\u043e \u0435\u0441\u043b\u0438 \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043e\u0434, \u0443\u0431\u0440\u0430\u0432 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 Foo.<\/p>\n<p><strong>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3.2: <\/strong>\u043d\u0435\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 Foo<\/p>\n<pre><code class=\"cs\">unsafe static void Main(string[] args) {     string str = \"Strings are immutable!\";          LibReverseString.Reverse(str);          Foo(); }  \/\/ Output: \/\/ Strings are immutable!<\/code><\/pre>\n<p>\u041c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0431\u0440\u0430\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 Foo \u0435\u0449\u0435 \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 Reverse, \u043d\u043e Reverse \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b. \u0418\u043b\u0438 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b? \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u0442\u0435\u043e\u0440\u0438\u044f \u043d\u0430\u0441\u0447\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d, \u043f\u0440\u043e\u0448\u0443 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u0442\u043e\u0447\u043d\u043e.<\/p>\n<p>\u0412 <strong>\u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 3.1, <\/strong>\u0432\u044b\u0437\u044b\u0432\u0430\u044f Foo \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437, \u043c\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c JIT-\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u043b\u044f Foo \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e str \u0441 \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 &#171;Strings are immutable!&#187;, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u043c\u044b \u0435\u0435 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c.<\/p>\n<p>\u0412 <strong>\u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 3.2<\/strong> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Foo \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0443. \u041b\u043e\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u044f Foo \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f str \u043d\u0435 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u0443\u044e \u0438\u043d\u0442\u0435\u0440\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443. \u0412 \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u044d\u0442\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438 \u043c\u043e\u0433\u0443 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 <strong>\u043b\u0438\u0441\u0442\u0438\u043d\u0433 3.3<\/strong>.<\/p>\n<p><strong>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 3.3<\/strong>: \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e JIT \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u0432\u0441\u0435\u0439 \u0441\u0431\u043e\u0440\u043a\u0438 TestApp.<\/p>\n<pre><code class=\"cs\">unsafe static void Main(string[] args) {     \/\/ Pre-JIT-compilation     foreach (var type in Assembly.Load(\"TestApp\").GetTypes())     {         foreach (var method in type.GetMethods(BindingFlags.DeclaredOnly |                             BindingFlags.NonPublic |                             BindingFlags.Public | BindingFlags.Instance |                             BindingFlags.Static))         {             System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod(method.MethodHandle);         }     }      string str = \"Strings are immutable!\";      LibReverseString.Reverse(str);      Foo(); }  \/\/ Output: \/\/ !elbatummi era sgnirtS<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u044f \u0432\u0437\u044f\u043b \u0443 <a href=\"https:\/\/www.codeproject.com\/script\/Membership\/View.aspx?mid=3643879\" rel=\"noopener noreferrer nofollow\">Vitaliy Liptchinsky<\/a> \u0438\u0437 \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e JIT-\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e (<a href=\"https:\/\/www.codeproject.com\/Articles\/31316\/Pre-compile-pre-JIT-your-assembly-on-the-fly-or-tr\" rel=\"noopener noreferrer nofollow\">https:\/\/www.codeproject.com\/Articles\/31316\/Pre-compile-pre-JIT-your-assembly-on-the-fly-or-tr<\/a>)<\/p>\n<h3>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 4<\/h3>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u044d\u0442\u043e \u043d\u0435\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e\u0431 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c.<\/p>\n<pre><code class=\"cs\">class Program {     public const string PI = \"3.14\";          unsafe static void Main(string[] args)     {         fixed (char* PIPtr = PI)         {             PIPtr[0] = '0';         }         Console.WriteLine(PI); \/\/ 0.14     }  }<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442, \u043d\u0430\u043f\u043e\u043c\u043d\u044e \u0432\u0430\u043c \u0435\u0449\u0435 \u0440\u0430\u0437, \u0441\u0442\u0440\u043e\u043a\u0430 &#8212; \u044d\u0442\u043e \u0410\u0414\u0420\u0415\u0421 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b. \u0418 \u0430\u0434\u0440\u0435\u0441 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u0439. \u0425\u043e\u0442\u044f \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u044f \u0434\u0443\u043c\u0430\u044e, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0442\u043e\u0436\u0435.<\/p>\n<p>Visual Studio \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u043a &#171;3.14&#187;.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 4.1:<\/strong> \u0415\u0441\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 Foo \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c Main<\/p>\n<pre><code class=\"cs\">unsafe static void Main(string[] args) {      fixed (char* PIPtr = PI)     {         PIPtr[0] = '0';     }        Console.WriteLine(PI); \/\/ 0.14      Foo(); }  private static void Foo() {     Console.WriteLine(PI); \/\/ 3.14 }  \/\/ Output: \/\/ 0.14 \/\/ 3.14<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0442\u0430\u043a\u0430\u044f \u0436\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u044f, \u043a\u0430\u043a \u0432 <strong>\u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 3<\/strong>. \u0420\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u0442 \u043d\u0435 \u0431\u0443\u0434\u0443, \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e JIT-\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e, \u0442\u043e Foo \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e &#171;0.14&#187;.<\/p>\n<h3>\u041b\u0438\u0441\u0442\u0438\u043d\u0433 5<\/h3>\n<p>\u0422\u0443\u0442 \u043c\u044b \u0432\u0438\u0434\u0438\u043c &#171;\u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0439&#187; \u043a\u043b\u0430\u0441\u0441. \u041c\u044b \u0436\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c Name, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u043c\u0435\u0435\u0442 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e readonly? \u041c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443, \u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e.<\/p>\n<pre><code class=\"cs\">public class ImmutablePerson {          public string Name { get; }      public ImmutablePerson(string name)     {         Name = name;     } }<\/code><\/pre>\n<pre><code class=\"cs\">ImmutablePerson person = new ImmutablePerson(\"William\");  Console.WriteLine(person.Name); \/\/ William  fixed (char* strPtr = person.Name) {     strPtr[0] = 'M';     strPtr[1] = 'i';     strPtr[2] = 'c';     strPtr[3] = 'h';     strPtr[4] = 'a';     strPtr[5] = 'e';     strPtr[6] = 'l'; }  Console.WriteLine(person.Name); \/\/ Michael<\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e Name \u0441 init-\u0430\u043a\u0441\u0435\u0441\u0441\u043e\u0440\u043e\u043c \u0438\u043b\u0438 \u0432\u043e\u0432\u0441\u0435 readonly \u043f\u043e\u043b\u0435\u043c:<\/p>\n<pre><code class=\"cs\">public string Name { get; init; }<\/code><\/pre>\n<pre><code class=\"cs\">public readonly string Name;<\/code><\/pre>\n<h3>\u041f\u043e\u0441\u043b\u0435\u0441\u043b\u043e\u0432\u0438\u0435<\/h3>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u043f\u0440\u043e\u0447\u0435\u043b \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0443\u0437\u043d\u0430\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0438\u043b\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e, \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u044f \u0445\u043e\u0442\u044c \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u0441\u043c\u043e\u0433 \u0432\u0430\u0441 \u0443\u0434\u0438\u0432\u0438\u0442\u044c.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 <strong>\u041a\u0441\u0435\u043d\u0438\u0438 \u041c\u043e\u0441\u0435\u0435\u043d\u043a\u043e\u0432\u043d\u044b<\/strong> (<a href=\"https:\/\/habr.com\/ru\/users\/kmoseenk\/\" rel=\"noopener noreferrer nofollow\">@kmoseenk<\/a>) \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043d\u043e \u043f\u0440\u043e \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a, \u0447\u0430\u0441\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432\u0437\u044f\u0442\u043e \u0438\u0437 \u043d\u0435\u0435 &#8212; <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/676680\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/company\/otus\/blog\/676680\/<\/a><\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u043d\u0438\u0439 \u043e\u0431 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 .NET \u044f \u0443\u0437\u043d\u0430\u043b \u0432 \u043a\u043d\u0438\u0433\u0435 &#8216;CLR via C#&#8217; \u043e\u0442 \u0430\u0432\u0442\u043e\u0440\u0430 \u0414\u0436\u0435\u0444\u0444\u0440\u0438 \u0420\u0438\u0445\u0442\u0435\u0440\u0430.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/707172\/\"> https:\/\/habr.com\/ru\/post\/707172\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-343005","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343005","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=343005"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343005\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}