{"id":2219,"date":"2018-01-30T16:21:53","date_gmt":"2018-01-30T07:21:53","guid":{"rendered":"http:\/\/okamurax.com\/?p=2219"},"modified":"2018-01-30T16:21:53","modified_gmt":"2018-01-30T07:21:53","slug":"c-%e3%82%af%e3%83%a9%e3%82%b9%e3%81%ae%e5%ae%9f%e9%a8%93","status":"publish","type":"post","link":"https:\/\/appbay.org\/?p=2219","title":{"rendered":"C# \u30af\u30e9\u30b9\u306e\u5b9f\u9a13"},"content":{"rendered":"<pre class=\"lang:c# decode:true  \">using System.Windows.Forms;\r\n\r\nnamespace WindowsFormsApp1\r\n{\r\n    public partial class Form1 : Form\r\n    {\r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n\r\n            \/\/\u52d5\u7684\u306a\u578b\uff1d\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u578b\u3002a.GetType()\r\n            \/\/\u9759\u7684\u306a\u578b\uff1d\u5909\u6570\u306e\u578b\u3002typeof(a)\r\n\r\n            \/\/\u9759\u7684\u306a\u578b\u3000\uff0f\u3000\u52d5\u7684\u306a\u578b\r\n            A a1 = new A();\r\n            B b1 = new B();\r\n            A a2 = new B();\r\n\r\n            MessageBox.Show(a1.GetType().ToString()); \/\/A\r\n            MessageBox.Show(b1.GetType().ToString()); \/\/B\r\n            MessageBox.Show(a2.GetType().ToString()); \/\/B\r\n            \/\/a2\u306fA\u306e\u578b\u306e\u5909\u6570\u3060\u3051\u3069\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306fB\u304c\u5165\u3063\u3066\u3044\u308b\u3002\r\n\r\n            MessageBox.Show(typeof(A).ToString()); \/\/A\r\n            MessageBox.Show(typeof(B).ToString()); \/\/B\r\n\r\n            \/\/\u5909\u6570\u540c\u58eb\u306e\u4ee3\u5165\u6642\u3001\u9759\u7684\u306a\u578b\u3067\u5224\u65ad\r\n            \/\/\u57fa\u5e95\u306e\u5909\u6570\u306b\u6d3e\u751f\u306e\u5909\u6570\u3092\u5165\u308c\u308b\uff1d\u30a2\u30c3\u30d7\u30ad\u30e3\u30b9\u30c8\u3002(\u5b89\u5168)\r\n            \/\/\u6d3e\u751f\u306e\u5909\u6570\u306b\u57fa\u5e95\u306e\u5909\u6570\u3092\u5165\u308c\u308b\uff1d\u30c0\u30a6\u30f3\u30ad\u30e3\u30b9\u30c8\u3002(\u4e0d\u53ef)\r\n\r\n            \/\/\u30e1\u30bd\u30c3\u30c9\u306f\u901a\u5e38\u9759\u7684\u306a\u578b\u3067\u547c\u3070\u308c\u308b\u3002\r\n            MessageBox.Show(a1.say()); \/\/A\r\n            MessageBox.Show(b1.say()); \/\/B\r\n            MessageBox.Show(a2.say()); \/\/A\r\n\r\n            \/\/Virtual\u306f\u52d5\u7684\u306a\u578b\u3067\u30e1\u30bd\u30c3\u30c9\u304c\u547c\u3070\u308c\u308b\u3002\r\n            \/\/Virtual\u30e1\u30bd\u30c3\u30c9\u306e\u518d\u5b9a\u7fa9Override\r\n\r\n            C c1 = new C();\r\n            D d1 = new D();\r\n            C c2 = new D();\r\n            MessageBox.Show(c1.say());\/\/C\r\n            MessageBox.Show(d1.say());\/\/D\r\n            MessageBox.Show(c2.say());\/\/D\r\n\r\n            \/\/\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306f\u3001\u57fa\u5e95\u30af\u30e9\u30b9\u304c\u547c\u3070\u308c\u3001\u6d3e\u751f\u30af\u30e9\u30b9\u304c\u547c\u3070\u308c\u308b\u3002\r\n        }\r\n    }\r\n\r\n    public class A\r\n    {\r\n        public string say() { return \"A\"; }\r\n    }\r\n    public class B : A\r\n    {\r\n        public string say() { return \"B\"; }\r\n    }\r\n    public class C\r\n    {\r\n        public virtual string say() { return \"C\"; }\r\n    }\r\n    public class D : C\r\n    {\r\n        public override string say() { return \"D\"; }\r\n        \/\/virtual\u30e1\u30bd\u30c3\u30c9\u3058\u3083\u306a\u3044\u3068override\u3067\u304d\u306a\u3044\u3002\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() {  &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/appbay.org\/?p=2219\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;C# \u30af\u30e9\u30b9\u306e\u5b9f\u9a13&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9],"class_list":["post-2219","post","type-post","status-publish","format-standard","hentry","category-1","tag-c-net"],"_links":{"self":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2219"}],"version-history":[{"count":1,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2219\/revisions"}],"predecessor-version":[{"id":2220,"href":"https:\/\/appbay.org\/index.php?rest_route=\/wp\/v2\/posts\/2219\/revisions\/2220"}],"wp:attachment":[{"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appbay.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}