{"id":56,"date":"2008-02-11T03:13:13","date_gmt":"2008-02-11T03:13:13","guid":{"rendered":""},"modified":"2008-02-11T03:13:13","modified_gmt":"2008-02-11T03:13:13","slug":"56","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=56","title":{"rendered":"C#\u4e2d\u7684&#34;\u88c5\u7bb1&#34;\u548c&#34;\u62c6\u7bb1&#34;"},"content":{"rendered":"<p>&nbsp;&nbsp; \u88c5\u7bb1\u548c\u62c6\u7bb1\uff1a\u4efb\u4f55\u503c\u7c7b\u578b\u3001\u5f15\u7528\u7c7b\u578b\u53ef\u4ee5\u548cobject\uff08\u5bf9\u8c61\uff09\u7c7b\u578b\u4e4b\u95f4\u8fdb\u884c\u8f6c\u6362\u3002\u88c5\u7bb1\u8f6c\u6362\u662f\u6307\u5c06\u4e00\u4e2a\u503c\u7c7b\u578b\u9690\u5f0f\u6216\u663e\u5f0f\u5730\u8f6c\u6362\u6210\u4e00\u4e2aobject\u7c7b\u578b\uff0c\u6216\u8005\u628a\u8fd9\u4e2a\u503c\u7c7b\u578b\u8f6c\u6362\u6210\u4e00\u4e2a\u88ab\u8be5\u503c\u7c7b\u578b\u5e94\u7528\u7684\u63a5\u53e3\u7c7b\u578b\uff08interface-type\uff09\u3002\u628a\u4e00\u4e2a\u503c\u7c7b\u578b\u7684\u503c\u88c5\u7bb1\uff0c\u5c31\u662f\u521b\u5efa\u4e00\u4e2aobject\u5b9e\u4f8b\u5e76\u5c06\u8fd9\u4e2a\u503c\u590d\u5236\u7ed9\u8fd9\u4e2aobject\uff0c\u88c5\u7bb1\u540e\u7684object\u5bf9\u8c61\u4e2d\u7684\u6570\u636e\u4f4d\u4e8e\u5806\u4e2d\uff0c\u5806\u4e2d\u7684\u5730\u5740\u5728\u6808\u4e2d\u3002\u88ab\u88c5\u7bb1\u7684\u7c7b\u578b\u7684\u503c\u662f\u4f5c\u4e3a\u4e00\u4e2a\u62f7\u8d1d\u8d4b\u7ed9\u5bf9\u8c61\u7684\u3002\u5982\uff1a <br \/>int i = 10;<br \/>object obj = i; \/\/\u9690\u5f0f\u88c5\u7bb1<br \/>object obj = object(i); \/\/\u663e\u5f0f\u88c5\u7bb1<br \/>if(obj is int) \/\/int<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(\u201cOK\u201d);<br \/>Console.WriteLine(obj.GetType()); \/\/System.Int32<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u6709\u4e24\u79cd\u65b9\u5f0f\u6765\u67e5\u770b\u5305\u88c5\u4ee5\u540e\u7684\u5f15\u7528\u5bf9\u8c61\u4e2d\u5305\u88c5\u7684\u539f\u59cb\u6570\u636e\u7684\u7c7b\u578b\u3002\u8981\u5224\u65ad\u539f\u59cb\u7c7b\u578b\u662f\u5426\u662f\u67d0\u4e2a\u7ed9\u5b9a\u7684\u539f\u5b50\u7c7b\u578b\uff0c\u7528is\uff1b\u5982\u679c\u8981\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u7528object\u7c7b\u7684GetType\u65b9\u6cd5\u3002<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u62c6\u7bb1\u8f6c\u6362\u662f\u6307\u5c06\u4e00\u4e2a\u5bf9\u8c61\u7c7b\u578b\u663e\u5f0f\u5730\u8f6c\u6362\u6210\u4e00\u4e2a\u503c\u7c7b\u578b\uff0c\u6216\u662f\u5c06\u4e00\u4e2a\u63a5\u53e3\u7c7b\u578b\u663e\u5f0f\u5730\u8f6c\u6362\u6210\u4e00\u4e2a\u6267\u884c\u8be5\u63a5\u53e3\u5730\u503c\u7c7b\u578b\u3002\u6ce8\u610f\u88c5\u7bb1\u64cd\u4f5c\u53ef\u4ee5\u9690\u5f0f\u8fdb\u884c\u4f46\u62c6\u7bb1\u64cd\u4f5c\u5fc5\u987b\u662f\u663e\u5f0f\u7684\u3002\u62c6\u7bb1\u8fc7\u7a0b\u5206\u6210\u4e24\u6b65\uff1a\u9996\u5148\uff0c\u68c0\u67e5\u8fd9\u4e2a\u5bf9\u8c61\u5b9e\u4f8b\uff0c\u770b\u5b83\u662f\u5426\u4e3a\u7ed9\u5b9a\u7684\u503c\u7c7b\u578b\u7684\u88c5\u7bb1\u503c\u3002\u7136\u540e\uff0c\u628a\u8fd9\u4e2a\u5b9e\u4f8b\u7684\u503c\u62f7\u8d1d\u7ed9\u503c\u7c7b\u578b\u7684\u53d8\u91cf\u3002\u6bd4\u5982\uff1a<br \/>int i = 10;<br \/>object obj = i;<br \/>int j = (int)obj;<br \/>\u6709\u4e24\u79cd\u65b9\u5f0f\u6765\u67e5\u770b\u5305\u88c5\u4ee5\u540e\u7684\u5f15\u7528\u5bf9\u8c61\u4e2d\u5305\u88c5\u7684\u539f\u59cb\u6570\u636e\u7684\u7c7b\u578b\u3002\u8981\u5224\u65ad\u539f\u59cb\u7c7b\u578b\u662f\u5426\u662f\u67d0\u4e2a\u7ed9\u5b9a\u7684\u539f\u5b50\u7c7b\u578b\uff0c\u7528is\uff1b\u5982\u679c\u8981\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u7528object\u7c7b\u7684GetType\u65b9\u6cd5\u3002<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u62c6\u7bb1\u8f6c\u6362\u662f\u6307\u5c06\u4e00\u4e2a\u5bf9\u8c61\u7c7b\u578b\u663e\u5f0f\u5730\u8f6c\u6362\u6210\u4e00\u4e2a\u503c\u7c7b\u578b\uff0c\u6216\u662f\u5c06\u4e00\u4e2a\u63a5\u53e3\u7c7b\u578b\u663e\u5f0f\u5730\u8f6c\u6362\u6210\u4e00\u4e2a\u6267\u884c\u8be5\u63a5\u53e3\u5730\u503c\u7c7b\u578b\u3002\u6ce8\u610f\u88c5\u7bb1\u64cd\u4f5c\u53ef\u4ee5\u9690\u5f0f\u8fdb\u884c\u4f46\u62c6\u7bb1\u64cd\u4f5c\u5fc5\u987b\u662f\u663e\u5f0f\u7684\u3002\u62c6\u7bb1\u8fc7\u7a0b\u5206\u6210\u4e24\u6b65\uff1a\u9996\u5148\uff0c\u68c0\u67e5\u8fd9\u4e2a\u5bf9\u8c61\u5b9e\u4f8b\uff0c\u770b\u5b83\u662f\u5426\u4e3a\u7ed9\u5b9a\u7684\u503c\u7c7b\u578b\u7684\u88c5\u7bb1\u503c\u3002\u7136\u540e\uff0c\u628a\u8fd9\u4e2a\u5b9e\u4f8b\u7684\u503c\u62f7\u8d1d\u7ed9\u503c\u7c7b\u578b\u7684\u53d8\u91cf\u3002\u6bd4\u5982\uff1a<br \/>int i = 10;<br \/>object obj = i;<br \/>int j = (int)obj;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp; \u88c5\u7bb1\u548c\u62c6\u7bb1\uff1a\u4efb\u4f55\u503c\u7c7b\u578b\u3001\u5f15\u7528\u7c7b\u578b\u53ef\u4ee5\u548cob&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-56","post","type-post","status-publish","format-standard","hentry","category-NET"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/56","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=56"}],"version-history":[{"count":0,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/56\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}