C# \u53ef\u7a7a\u7c7b\u578b\uff08Nullable\uff09<\/strong><\/div>\nC# \u63d0\u4f9b\u4e86\u4e00\u4e2a\u7279\u6b8a\u7684\u6570\u636e\u7c7b\u578b\uff0cnullable \u7c7b\u578b\uff08\u53ef\u7a7a\u7c7b\u578b\uff09\uff0c\u53ef\u7a7a\u7c7b\u578b\u53ef\u4ee5\u8868\u793a\u5176\u57fa\u7840\u503c\u7c7b\u578b\u6b63\u5e38\u8303\u56f4\u5185\u7684\u503c\uff0c\u518d\u52a0\u4e0a\u4e00\u4e2a null \u503c\u3002<\/p>\n
\u4f8b\u5982\uff0cNullable<Int32>\uff0c\u8bfb\u4f5c\"\u53ef\u7a7a\u7684 Int32\"\uff0c\u53ef\u4ee5\u88ab\u8d4b\u503c\u4e3a -2,147,483,648 \u5230 2,147,483,647 \u4e4b\u95f4\u7684\u4efb\u610f\u503c\uff0c\u4e5f\u53ef\u4ee5\u88ab\u8d4b\u503c\u4e3a null \u503c\u3002\u7c7b\u4f3c\u7684\uff0cNullable< bool> \u53d8\u91cf\u53ef\u4ee5\u88ab\u8d4b\u503c\u4e3a true \u6216 false \u6216 null\u3002<\/p>\n
\u5728\u5904\u7406\u6570\u636e\u5e93\u548c\u5176\u4ed6\u5305\u542b\u53ef\u80fd\u672a\u8d4b\u503c\u7684\u5143\u7d20\u7684\u6570\u636e\u7c7b\u578b\u65f6\uff0c\u5c06 null \u8d4b\u503c\u7ed9\u6570\u503c\u7c7b\u578b\u6216\u5e03\u5c14\u578b\u7684\u529f\u80fd\u7279\u522b\u6709\u7528\u3002\u4f8b\u5982\uff0c\u6570\u636e\u5e93\u4e2d\u7684\u5e03\u5c14\u578b\u5b57\u6bb5\u53ef\u4ee5\u5b58\u50a8\u503c true \u6216 false\uff0c\u6216\u8005\uff0c\u8be5\u5b57\u6bb5\u4e5f\u53ef\u4ee5\u672a\u5b9a\u4e49\u3002<\/p>\n
\u58f0\u660e\u4e00\u4e2a nullable \u7c7b\u578b\uff08\u53ef\u7a7a\u7c7b\u578b\uff09\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n
<data_type> ? <variable_name> = null;<\/pre>\n\u4e0b\u9762\u7684\u5b9e\u4f8b\u6f14\u793a\u4e86\u53ef\u7a7a\u6570\u636e\u7c7b\u578b\u7684\u7528\u6cd5\uff1a<\/p>\n
\u5b9e\u4f8b<\/p>\n
using System;\r\nnamespace CalculatorApplication\r\n{\r\n class NullablesAtShow\r\n {\r\n static void Main(string[] args)\r\n {\r\n int? num1 = null;\r\n int? num2 = 45;\r\n double? num3 = new double?();\r\n double? num4 = 3.14157;\r\n \r\n bool? boolval = new bool?();\r\n\r\n \/\/ \u663e\u793a\u503c\r\n \r\n Console.WriteLine(\"\u663e\u793a\u53ef\u7a7a\u7c7b\u578b\u7684\u503c\uff1a {0}, {1}, {2}, {3}\",\r\n num1, num2, num3, num4);\r\n Console.WriteLine(\"\u4e00\u4e2a\u53ef\u7a7a\u7684\u5e03\u5c14\u503c\uff1a {0}\", boolval);\r\n Console.ReadLine();\r\n\r\n }\r\n }\r\n}<\/pre>\n\u5f53\u4e0a\u9762\u7684\u4ee3\u7801\u88ab\u7f16\u8bd1\u548c\u6267\u884c\u65f6\uff0c\u5b83\u4f1a\u4ea7\u751f\u4e0b\u5217\u7ed3\u679c\uff1a<\/p>\n
\u663e\u793a\u53ef\u7a7a\u7c7b\u578b\u7684\u503c\uff1a , 45, , 3.14157\r\n\u4e00\u4e2a\u53ef\u7a7a\u7684\u5e03\u5c14\u503c\uff1a<\/pre>\nNull \u5408\u5e76\u8fd0\u7b97\u7b26\uff08 ?? \uff09<\/strong><\/div>\nNull \u5408\u5e76\u8fd0\u7b97\u7b26\u7528\u4e8e\u5b9a\u4e49\u53ef\u7a7a\u7c7b\u578b\u548c\u5f15\u7528\u7c7b\u578b\u7684\u9ed8\u8ba4\u503c\u3002Null \u5408\u5e76\u8fd0\u7b97\u7b26\u4e3a\u7c7b\u578b\u8f6c\u6362\u5b9a\u4e49\u4e86\u4e00\u4e2a\u9884\u8bbe\u503c\uff0c\u4ee5\u9632\u53ef\u7a7a\u7c7b\u578b\u7684\u503c\u4e3a Null\u3002Null \u5408\u5e76\u8fd0\u7b97\u7b26\u628a\u64cd\u4f5c\u6570\u7c7b\u578b\u9690\u5f0f\u8f6c\u6362\u4e3a\u53e6\u4e00\u4e2a\u53ef\u7a7a\uff08\u6216\u4e0d\u53ef\u7a7a\uff09\u7684\u503c\u7c7b\u578b\u7684\u64cd\u4f5c\u6570\u7684\u7c7b\u578b\u3002<\/p>\n
\u5982\u679c\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570\u7684\u503c\u4e3a null\uff0c\u5219\u8fd0\u7b97\u7b26\u8fd4\u56de\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u6570\u7684\u503c\uff0c\u5426\u5219\u8fd4\u56de\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570\u7684\u503c\u3002\u4e0b\u9762\u7684\u5b9e\u4f8b\u6f14\u793a\u4e86\u8fd9\u70b9\uff1a<\/p>\n
\u5b9e\u4f8b<\/p>\n
using System;\r\nnamespace CalculatorApplication\r\n{\r\n class NullablesAtShow\r\n {\r\n \r\n static void Main(string[] args)\r\n {\r\n \r\n double? num1 = null;\r\n double? num2 = 3.14157;\r\n double num3;\r\n num3 = num1 ?? 5.34; \/\/ num1 \u5982\u679c\u4e3a\u7a7a\u503c\u5219\u8fd4\u56de 5.34\r\n Console.WriteLine(\"num3 \u7684\u503c\uff1a {0}\", num3);\r\n num3 = num2 ?? 5.34;\r\n Console.WriteLine(\"num3 \u7684\u503c\uff1a {0}\", num3);\r\n Console.ReadLine();\r\n\r\n }\r\n }\r\n}<\/pre>\n\u5f53\u4e0a\u9762\u7684\u4ee3\u7801\u88ab\u7f16\u8bd1\u548c\u6267\u884c\u65f6\uff0c\u5b83\u4f1a\u4ea7\u751f\u4e0b\u5217\u7ed3\u679c\uff1a<\/p>\n
num3 \u7684\u503c\uff1a 5.34\r\nnum3 \u7684\u503c\uff1a 3.14157<\/pre>\n","protected":false},"excerpt":{"rendered":"? \u5355\u95ee\u53f7\u7528\u4e8e\u5bf9 int\u3001double\u3001bool \u7b49\u65e0\u6cd5\u76f4\u63a5\u8d4b\u503c\u4e3a null \u7684\u6570\u636e\u7c7b\u578b\u8fdb\u884c null \u7684\u8d4b\u503c […]<\/p>\n","protected":false},"author":321,"featured_media":236254,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-236252","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=236252"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236252\/revisions"}],"predecessor-version":[{"id":236258,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236252\/revisions\/236258"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/236254"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=236252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=236252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=236252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}