{"id":3473,"date":"2025-04-06T23:27:48","date_gmt":"2025-04-06T15:27:48","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=3473"},"modified":"2025-04-06T23:27:48","modified_gmt":"2025-04-06T15:27:48","slug":"c-%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%ef%bc%88c-data-types%ef%bc%89%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/04\/06\/c-%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%ef%bc%88c-data-types%ef%bc%89%e8%af%a6%e8%a7%a3\/","title":{"rendered":"C# \u6570\u636e\u7c7b\u578b\uff08C# Data Types\uff09\u8be6\u89e3"},"content":{"rendered":"\n<p>\u672c\u6587\u7ae0\u6df1\u5165\u8bb2\u89e3 <strong>C# \u6570\u636e\u7c7b\u578b\uff08C# Data Types\uff09<\/strong>\uff0c<strong>\u5168\u9762\u3001\u7cfb\u7edf<\/strong>\u5730\u4ecb\u7ecd C# \u652f\u6301\u7684\u5404\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u901a\u8fc7\u672c\u7ae0\u8282\u4f60\u5c06\u4e86\u89e3\u5230\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C# \u4e2d\u7684\u6570\u636e\u7c7b\u578b\u5206\u7c7b<\/li>\n\n\n\n<li>\u6bcf\u79cd\u7c7b\u578b\u7684\u7528\u9014\u548c\u7279\u6027<\/li>\n\n\n\n<li>\u5185\u5b58\u5927\u5c0f\u3001\u9ed8\u8ba4\u503c\u3001\u8303\u56f4<\/li>\n\n\n\n<li>\u7c7b\u578b\u8f6c\u6362<\/li>\n\n\n\n<li>\u5b98\u65b9\u6587\u6863\u94fe\u63a5<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udccc \u76ee\u5f55\u5bfc\u822a<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>C# \u6570\u636e\u7c7b\u578b\u603b\u89c8<\/li>\n\n\n\n<li>\u503c\u7c7b\u578b\uff08Value Types\uff09<\/li>\n\n\n\n<li>\u5f15\u7528\u7c7b\u578b\uff08Reference Types\uff09<\/li>\n\n\n\n<li>\u6307\u9488\u7c7b\u578b\uff08Pointer Types\uff09<\/li>\n\n\n\n<li>\u7c7b\u578b\u8f6c\u6362\uff08Type Conversion\uff09<\/li>\n\n\n\n<li>var \u4e0e dynamic \u5173\u952e\u5b57<\/li>\n\n\n\n<li>Nullable \u7c7b\u578b\uff08\u53ef\u7a7a\u503c\u7c7b\u578b\uff09<\/li>\n\n\n\n<li>\u7c7b\u578b\u68c0\u67e5\u4e0e\u8f6c\u6362\u64cd\u4f5c\u7b26<\/li>\n\n\n\n<li>\u5b98\u65b9\u6743\u5a01\u6587\u6863\u94fe\u63a5<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1\ufe0f\u20e3 \u6570\u636e\u7c7b\u578b\u603b\u89c8<\/h2>\n\n\n\n<p>C# \u6570\u636e\u7c7b\u578b\u4e3b\u8981\u5206\u4e3a\u4e09\u7c7b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5206\u7c7b<\/th><th>\u793a\u4f8b<\/th><\/tr><\/thead><tbody><tr><td>\u503c\u7c7b\u578b<\/td><td><code>int<\/code>, <code>float<\/code>, <code>bool<\/code>, <code>char<\/code><\/td><\/tr><tr><td>\u5f15\u7528\u7c7b\u578b<\/td><td><code>string<\/code>, <code>object<\/code>, \u81ea\u5b9a\u4e49\u7c7b<\/td><\/tr><tr><td>\u6307\u9488\u7c7b\u578b\uff08\u4e0d\u5e38\u7528\uff09<\/td><td><code>int*<\/code>, <code>char*<\/code>\uff08\u9700 unsafe\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff1a<br>\ud83d\udc49 <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/builtin-types\/built-in-types\">Built-in Types &#8211; Microsoft Docs<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2\ufe0f\u20e3 \u503c\u7c7b\u578b\uff08Value Types\uff09<\/h2>\n\n\n\n<p>\u503c\u7c7b\u578b\u76f4\u63a5\u5305\u542b\u6570\u636e\uff0c\u5206\u914d\u5728 <strong>\u6808\u4e0a<\/strong>\uff0c\u53d8\u91cf\u62e5\u6709\u81ea\u5df1\u7684\u526f\u672c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 \u5e38\u89c1\u503c\u7c7b\u578b<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7c7b\u578b<\/th><th>\u5360\u7528\u7a7a\u95f4<\/th><th>\u9ed8\u8ba4\u503c<\/th><th>\u53d6\u503c\u8303\u56f4\uff08\u90e8\u5206\uff09<\/th><\/tr><\/thead><tbody><tr><td><code>int<\/code><\/td><td>4 \u5b57\u8282<\/td><td><code>0<\/code><\/td><td>-2,147,483,648 \u5230 2,147,483,647<\/td><\/tr><tr><td><code>long<\/code><\/td><td>8 \u5b57\u8282<\/td><td><code>0L<\/code><\/td><td>\u00b19\u00d710\u00b9\u2078<\/td><\/tr><tr><td><code>float<\/code><\/td><td>4 \u5b57\u8282<\/td><td><code>0.0f<\/code><\/td><td>\u00b11.5\u00d710\u207b\u2074\u2075 \u5230 \u00b13.4\u00d710\u00b3\u2078<\/td><\/tr><tr><td><code>double<\/code><\/td><td>8 \u5b57\u8282<\/td><td><code>0.0d<\/code><\/td><td>\u00b15.0\u00d710\u207b\u00b3\u00b2\u2074 \u5230 \u00b11.7\u00d710\u00b3\u2070\u2078<\/td><\/tr><tr><td><code>decimal<\/code><\/td><td>16 \u5b57\u8282<\/td><td><code>0.0m<\/code><\/td><td>\u00b11.0\u00d710\u207b\u00b2\u2078 \u5230 \u00b17.9\u00d710\u00b2\u2078<\/td><\/tr><tr><td><code>bool<\/code><\/td><td>1 \u5b57\u8282<\/td><td><code>false<\/code><\/td><td><code>true<\/code> \u6216 <code>false<\/code><\/td><\/tr><tr><td><code>char<\/code><\/td><td>2 \u5b57\u8282<\/td><td><code>'\\0'<\/code><\/td><td>Unicode \u5b57\u7b26\uff0c\u5982 <code>'A'<\/code>\u3001<code>'\u4e2d'<\/code><\/td><\/tr><tr><td><code>byte<\/code><\/td><td>1 \u5b57\u8282<\/td><td><code>0<\/code><\/td><td>0 \u5230 255<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>int age = 30;\nfloat price = 19.99f;\nbool isAdmin = false;\nchar grade = 'A';<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3\ufe0f\u20e3 \u5f15\u7528\u7c7b\u578b\uff08Reference Types\uff09<\/h2>\n\n\n\n<p>\u5f15\u7528\u7c7b\u578b\u5b58\u50a8 <strong>\u5f15\u7528\u5730\u5740<\/strong>\uff0c\u5b9e\u9645\u6570\u636e\u5b58\u5728\u4e8e <strong>\u5806<\/strong> \u4e0a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 \u5e38\u89c1\u5f15\u7528\u7c7b\u578b<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7c7b\u578b<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>string<\/code><\/td><td>\u5b57\u7b26\u4e32\uff08\u4e0d\u53ef\u53d8\uff09<\/td><\/tr><tr><td><code>object<\/code><\/td><td>\u6240\u6709\u7c7b\u578b\u7684\u57fa\u7c7b<\/td><\/tr><tr><td>\u81ea\u5b9a\u4e49\u7c7b<\/td><td><code>class<\/code>, <code>interface<\/code> \u7b49<\/td><\/tr><tr><td><code>array<\/code><\/td><td>\u6570\u7ec4\uff0c\u5982 <code>int[]<\/code>, <code>string[]<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>string name = \"Alice\";\nobject obj = 123;\nint&#91;] scores = {90, 80, 70};<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4\ufe0f\u20e3 \u6307\u9488\u7c7b\u578b\uff08Pointer Types\uff09<\/h2>\n\n\n\n<p>\u53ea\u6709\u5728 <strong>unsafe \u4e0a\u4e0b\u6587\u4e2d<\/strong> \u624d\u80fd\u4f7f\u7528\uff0c\u4e3b\u8981\u7528\u4e8e\u7cfb\u7edf\u7f16\u7a0b\u6216\u6027\u80fd\u5173\u952e\u4ee3\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>unsafe\n{\n    int x = 10;\n    int* px = &amp;x;\n    Console.WriteLine(*px);  \/\/ \u8f93\u51fa\uff1a10\n}<\/code><\/pre>\n\n\n\n<p>\u26a0\ufe0f \u4f7f\u7528 <code>unsafe<\/code> \u9700\u8981\u5f00\u542f\u7f16\u8bd1\u5668\u8bbe\u7f6e\uff0c\u5e76\u4e0d\u63a8\u8350\u4e00\u822c\u4e1a\u52a1\u903b\u8f91\u4e2d\u4f7f\u7528\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5\ufe0f\u20e3 \u7c7b\u578b\u8f6c\u6362\uff08Type Conversion\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd38 \u9690\u5f0f\u8f6c\u6362\uff08\u5c0f\u8f6c\u5927\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int a = 100;\nlong b = a; \/\/ \u81ea\u52a8\u8f6c\u6362<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd38 \u663e\u5f0f\u8f6c\u6362\uff08\u5927\u8f6c\u5c0f\uff0c\u9700\u5f3a\u5236\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>double x = 12.34;\nint y = (int)x; \/\/ \u624b\u52a8\u8f6c\u6362\uff0cy = 12<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd38 <code>Convert<\/code> \u7c7b<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string str = \"123\";\nint num = Convert.ToInt32(str);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">6\ufe0f\u20e3 var \u4e0e dynamic<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 <code>var<\/code>\uff1a\u7f16\u8bd1\u65f6\u7c7b\u578b\u63a8\u65ad\uff08\u9759\u6001\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>var age = 20;       \/\/ int\nvar name = \"Tom\";   \/\/ string<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\ud83d\udccc \u4e00\u65e6\u7c7b\u578b\u88ab\u63a8\u65ad\uff0c\u4e0d\u80fd\u518d\u6539\u53d8\u3002<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd39 <code>dynamic<\/code>\uff1a\u8fd0\u884c\u65f6\u7ed1\u5b9a\uff08\u52a8\u6001\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>dynamic x = 10;\nx = \"hello\"; \/\/ \u53ef\u53d8\u7c7b\u578b\uff0c\u4f46\u5b58\u5728\u8fd0\u884c\u65f6\u9519\u8bef\u98ce\u9669<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">7\ufe0f\u20e3 Nullable \u7c7b\u578b\uff08\u53ef\u7a7a\u503c\uff09<\/h2>\n\n\n\n<p>\u503c\u7c7b\u578b\u4e0d\u80fd\u4e3a <code>null<\/code>\uff0c\u9664\u975e\u4f7f\u7528 <code>?<\/code> \u4fee\u9970\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int? age = null;\n\nif (age.HasValue)\n{\n    Console.WriteLine(age.Value);\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">8\ufe0f\u20e3 \u7c7b\u578b\u68c0\u67e5\u4e0e\u8f6c\u6362\u64cd\u4f5c\u7b26<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u64cd\u4f5c\u7b26<\/th><th>\u793a\u4f8b<\/th><th>\u542b\u4e49<\/th><\/tr><\/thead><tbody><tr><td><code>is<\/code><\/td><td><code>obj is string<\/code><\/td><td>\u7c7b\u578b\u5224\u65ad<\/td><\/tr><tr><td><code>as<\/code><\/td><td><code>obj as string<\/code><\/td><td>\u7c7b\u578b\u8f6c\u6362\uff0c\u5931\u8d25\u8fd4\u56de null<\/td><\/tr><tr><td><code>typeof<\/code><\/td><td><code>typeof(int)<\/code><\/td><td>\u83b7\u53d6\u7c7b\u578b\u4fe1\u606f<\/td><\/tr><tr><td><code>.GetType()<\/code><\/td><td><code>x.GetType()<\/code><\/td><td>\u8fd0\u884c\u65f6\u83b7\u53d6\u5b9e\u4f8b\u7c7b\u578b<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"> 9\ufe0f\u20e3 \u5b98\u65b9\u6743\u5a01\u6587\u6863\u94fe\u63a5<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ud83e\uddfe C# \u7c7b\u578b\u7cfb\u7edf\u6982\u8ff0\uff1a<br>https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/tour-of-csharp\/types<\/li>\n\n\n\n<li>\ud83d\udce6 \u6240\u6709\u5185\u7f6e\u7c7b\u578b\uff08\u542b\u5927\u5c0f\u3001\u8303\u56f4\uff09\uff1a<br>https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/builtin-types\/built-in-types<\/li>\n\n\n\n<li>\ud83d\udd04 \u7c7b\u578b\u8f6c\u6362\uff1a<br>https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/programming-guide\/types\/type-conversions<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"> \u603b\u7ed3<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7c7b\u578b\u5206\u7c7b<\/th><th>\u793a\u4f8b<\/th><th>\u7279\u70b9<\/th><\/tr><\/thead><tbody><tr><td>\u503c\u7c7b\u578b<\/td><td><code>int<\/code>, <code>bool<\/code>, <code>char<\/code><\/td><td>\u6808\u4e0a\u5206\u914d\uff0c\u9ad8\u6027\u80fd<\/td><\/tr><tr><td>\u5f15\u7528\u7c7b\u578b<\/td><td><code>string<\/code>, <code>object<\/code>, \u7c7b<\/td><td>\u5806\u4e0a\u5206\u914d\uff0c\u7075\u6d3b\u4f46\u9700\u6ce8\u610f\u5185\u5b58\u7ba1\u7406<\/td><\/tr><tr><td>\u6307\u9488\u7c7b\u578b<\/td><td><code>int*<\/code>, <code>char*<\/code><\/td><td>\u9ad8\u7ea7\u7528\u6cd5\uff0c\u9700 <code>unsafe<\/code><\/td><\/tr><tr><td>Nullable<\/td><td><code>int?<\/code><\/td><td>\u503c\u7c7b\u578b\u4e5f\u53ef\u4e3a null<\/td><\/tr><tr><td>\u52a8\u6001\u7c7b\u578b<\/td><td><code>dynamic<\/code><\/td><td>\u8fd0\u884c\u65f6\u7075\u6d3b\uff0c\u4f4e\u6027\u80fd\u3001\u6613\u9519<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u662f\u5426\u9700\u8981\u6211\u63a5\u4e0b\u6765\u5e2e\u4f60\u6574\u7406\u300cC# \u6d41\u7a0b\u63a7\u5236\u8bed\u53e5\u300d\u6216\u300cC# \u7c7b\u4e0e\u5bf9\u8c61\u300d\u7684\u8be6\u7ec6\u5b66\u4e60\u8d44\u6599\uff1f\u6211\u53ef\u4ee5\u7ee7\u7eed\u4e3a\u4f60\u505a\u7cfb\u5217\u8bb2\u89e3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7ae0\u6df1\u5165\u8bb2\u89e3 C# \u6570\u636e\u7c7b\u578b\uff08C# Data Types\uff09\uff0c\u5168\u9762\u3001\u7cfb\u7edf\u5730\u4ecb\u7ecd C# \u652f\u6301\u7684\u5404\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u901a\u8fc7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3474,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[83],"tags":[],"class_list":["post-3473","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=3473"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3473\/revisions"}],"predecessor-version":[{"id":3475,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3473\/revisions\/3475"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media\/3474"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=3473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=3473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=3473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}