{"id":257,"date":"2022-06-24T14:54:49","date_gmt":"2022-06-24T06:54:49","guid":{"rendered":"https:\/\/www.fengjijiao.cn\/?p=257"},"modified":"2022-06-24T14:54:50","modified_gmt":"2022-06-24T06:54:50","slug":"c%e5%8f%98%e9%87%8f%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.fengjijiao.cn\/?p=257","title":{"rendered":"C#\u53d8\u91cf\u7c7b\u578b"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>using System;\r\n\r\nnamespace ConsoleApp1\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string&#91;] args)\r\n        {\r\n            Console.WriteLine(\"ok\");\r\n            String str = \"String\";\r\n            char&#91;] chs = str.ToCharArray();\r\n            for(int i = 0; i &lt; chs.Length; i++)\r\n            {\r\n                Console.WriteLine(chs&#91;i]);\r\n            }\r\n            \/\/\u83b7\u53d6\u53d8\u91cf\u7c7b\u578b\u5927\u5c0f\r\n            Console.WriteLine(\"size of bool: {0}\", sizeof(bool));\r\n            \/\/\u503c\u7c7b\u578b\r\n            \/*bool v0 = true;\r\n            byte v1 = 0;\/\/0-255   8\r\n            char v2 = '\\0';\/\/U+0000 ~ U+ffff   16\r\n            decimal v3 = 0.0M;\/\/-7.9x10^28~7.9x10^28   128\u4f4d\u7cbe\u5ea6\u5341\u8fdb\u5236\u503c\uff0c28-29\u6709\u6548\u4f4d\u6570\r\n            double v4 = 0.0D;\/\/(+\/-)5.0x10^-324~(+\/-)1.7x10^308   64\u4f4d\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u578b\r\n            float v5 = 0.0F;\/\/-3.4x10^38~3.4x10^38    32\u4f4d\u5355\u7cbe\u5ea6\u6d6e\u70b9\u578b\r\n            int v6 = 0;\/\/-2147483648~2147483647    32\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u7c7b\u578b\r\n            long v7 = 0L;\/\/-9,233,372,036,854,775,808 ~ 9,223,372,036,854,775,807   64\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u7c7b\u578b\r\n            sbyte v8 = 0;\/\/-128~127   8\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u7c7b\u578b\r\n            short v9 = 0;\/\/-32768~32767   16\u4f4d\u6709\u7b26\u53f7\u6574\u6570\u7c7b\u578b\r\n            uint v10 = 0;\/\/0~4294,967,295   32\u4f4d\u65e0\u7b26\u53f7\u6574\u6570\u7c7b\u578b\r\n            ulong v11 = 0;\/\/0~18,446,744,073,709,551,615   64\u4f4d\u65e0\u7b26\u53f7\u6574\u6570\u7c7b\u578b\r\n            ushort v12 = 0;\/\/0~65,535   16\u4f4d\u65e0\u7b26\u53f7\u6574\u6570\u7c7b\u578b*\/\r\n            \/\/\u5f15\u7528\u7c7b\u578b\r\n            \/\/1.\u5bf9\u8c61\u7c7b\u578bobject\uff08\u6240\u6709\u6570\u636e\u7c7b\u578b\u7684\u7ec8\u6781\u57fa\u7c7b\uff09\r\n            \/\/\u88c5\u7bb1\uff08\u503c\u7c7b\u578b->\u5bf9\u8c61\u7c7b\u578b\uff09\r\n            int v13 = 123;\r\n            object v14;\r\n            v14 = v13;\r\n            Console.WriteLine(\"v14: {0}\", v14);\r\n            \/\/\u62c6\u7bb1\uff08\u5bf9\u8c61\u7c7b\u578b->\u503c\u7c7b\u578b\uff09\r\n            int v15 = (int) v14;\/\/\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\r\n            Console.WriteLine(\"v15: {0}\", v15);\r\n            \/\/2.\u52a8\u6001\u7c7b\u578bdynamic\r\n            \/\/\u4efb\u4f55\u7c7b\u578b\u7684\u503c\u5728\u52a8\u6001\u6570\u636e\u7c7b\u578b\u53d8\u91cf\u4e2d\uff0c\u53d8\u91cf\u7684\u7c7b\u578b\u68c0\u67e5\u662f\u5728\u8fd0\u884c\u65f6\u53d1\u751f\u7684\u3002\r\n            \/\/dynamic &lt;variable_name> = value;\r\n            dynamic d = 20;\r\n            Console.WriteLine(\"dynamic d value is: {0}\", d);\r\n            d += 0.1999;\r\n            Console.WriteLine(\"dynamic d value is: {0}\", d);\r\n            d -= 0.1999;\r\n            Console.WriteLine(\"dynamic d value is: {0}\", d);\r\n            d = '\\0';\r\n            Console.WriteLine(\"dynamic d value is: {0}\", d);\r\n            double d1 = 20;\r\n            Console.WriteLine(\"double d1 value is: {0}\", d1);\r\n            \/\/\u52a8\u6001\u7c7b\u578b\u4e0e\u5bf9\u8c61\u7c7b\u578b\u76f8\u4f3c\uff0c\u4f46\u662f\u5bf9\u8c61\u7c7b\u578b\u53d8\u91cf\u7684\u7c7b\u578b\u68c0\u67e5\u662f\u5728\u7f16\u8bd1\u65f6\u53d1\u751f\u7684\uff0c\u800c\u52a8\u6001\u7c7b\u578b\u53d8\u91cf\u7684\u7c7b\u578b\u68c0\u67e5\u662f\u5728\u8fd0\u884c\u65f6\u53d1\u751f\u7684\u3002\r\n            \/\/3.\u5b57\u7b26\u4e32\u7c7b\u578bString\r\n            String str1 = \"o\\nk\";\r\n            String str2 = @\"o\\nk\";\r\n            Console.WriteLine(\"str1 is: {0}\", str1);\r\n            Console.WriteLine(\"str2 is: {0}\", str2);\r\n            \/\/str2\u524d\u4f7f\u7528@\uff0c\u5c06\u8f6c\u4e49\u5b57\u7b26\u5f53\u4f5c\u666e\u901a\u5b57\u7b26\u5bf9\u5f85\u3002\r\n            \/\/4.\u7528\u6237\u81ea\u5b9a\u4e49\u5f15\u7528\u7c7b\u578b\u6709\uff1aclass\u3001interface\u6216delegate\u3002\r\n\r\n            \/\/\u6307\u9488\u7c7b\u578b\r\n            \/\/\u8fd0\u884cunsafe\u4ee3\u7801\u5757\uff0c\u9700\u8981\u5728vs\u9879\u76ee->\u751f\u6210\u4e2d\u5f00\u542f\u5141\u8bb8\u4e0d\u5b89\u5168\u7684\u4ee3\u7801\u5757\r\n            unsafe\r\n            {\r\n                int p1 = 99;\r\n                Console.WriteLine(\"p1 is: {0}\", p1);\r\n                int* p2 = &amp;p1;\r\n                Console.WriteLine(\"p2 is: {0}\", *p2);\r\n                p1++;\r\n                Console.WriteLine(\"p2 is: {0}\", *p2);\r\n            }\r\n            \r\n            Console.ReadKey();\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/www.fengjijiao.cn\/index.php?rest_route=\/wp\/v2\/posts\/257"}],"collection":[{"href":"https:\/\/www.fengjijiao.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fengjijiao.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fengjijiao.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fengjijiao.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=257"}],"version-history":[{"count":1,"href":"https:\/\/www.fengjijiao.cn\/index.php?rest_route=\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":258,"href":"https:\/\/www.fengjijiao.cn\/index.php?rest_route=\/wp\/v2\/posts\/257\/revisions\/258"}],"wp:attachment":[{"href":"https:\/\/www.fengjijiao.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fengjijiao.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fengjijiao.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}