[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-572629-105":53,"doc-detail-572629-en":130},{"code":4,"msg":5,"data":6},0,"success",[7,14,19,24,29,34,39,44,49],{"id":8,"doc_module":9,"doc_module_name":10,"category_name":11,"show_sort_weight":12,"slug":13},11,1,"Template","Presentations",90,"presentations",{"id":15,"doc_module":9,"doc_module_name":10,"category_name":16,"show_sort_weight":17,"slug":18},12,"Resumes",80,"resumes",{"id":20,"doc_module":9,"doc_module_name":10,"category_name":21,"show_sort_weight":22,"slug":23},14,"Invoices",70,"invoices",{"id":25,"doc_module":9,"doc_module_name":10,"category_name":26,"show_sort_weight":27,"slug":28},15,"Posters",60,"posters",{"id":30,"doc_module":9,"doc_module_name":10,"category_name":31,"show_sort_weight":32,"slug":33},16,"Social Media",50,"social-media",{"id":35,"doc_module":9,"doc_module_name":10,"category_name":36,"show_sort_weight":37,"slug":38},17,"Forms",40,"forms",{"id":40,"doc_module":9,"doc_module_name":10,"category_name":41,"show_sort_weight":42,"slug":43},18,"Letters",30,"letters",{"id":45,"doc_module":9,"doc_module_name":10,"category_name":46,"show_sort_weight":47,"slug":48},21,"Paper Templates",5,"papers-templates",{"id":50,"doc_module":9,"doc_module_name":10,"category_name":51,"show_sort_weight":4,"slug":52},158,"General","general-158",{"code":4,"msg":54,"data":55},"ok",{"site_id":56,"language":57,"slug":58,"title":59,"keywords":60,"description":61,"schema_data":62,"social_meta":123,"head_meta":125,"extra_data":127,"updated_unix":129},105,"en","advanced-c-inheritance-interfaces-delegates-exceptions","Advanced C# - Inheritance, Interfaces, Delegates, Exceptions","","Advanced C#讲解围绕继承机制与多态行为展开，包括类型赋值与运行时类型检查（is）、安全与不安全类型转换（as、强制转换）以及重写规则（virtual/override、签名一致性、静态方法不可重写）。内容还对成员隐藏（new）与隐藏结合重载的动态绑定差异进行举例，并讨论“脆弱基类”问题的版本兼容风险：基类实现变更可能导致子类行为在未重新编译时偏离预期。",{"@graph":63,"@context":122},[64,80,101],{"@type":65,"itemListElement":66},"BreadcrumbList",[67,71,74,77],{"item":68,"name":69,"@type":70,"position":9},"https://docshare.wps.com","Home","ListItem",{"item":72,"name":10,"@type":70,"position":73},"https://docshare.wps.com/template/",2,{"item":75,"name":11,"@type":70,"position":76},"https://docshare.wps.com/template/presentations/",3,{"item":78,"name":59,"@type":70,"position":79},"https://docshare.wps.com/template/advanced-c-inheritance-interfaces-delegates-exceptions/572629/",4,{"url":78,"name":59,"@type":81,"image":82,"author":87,"headline":59,"publisher":90,"fileFormat":93,"inLanguage":57,"description":61,"dateModified":94,"datePublished":95,"encodingFormat":93,"isAccessibleForFree":96,"interactionStatistic":97},"DigitalDocument",{"url":83,"@type":84,"width":85,"height":86},"https://docshare.wps.com/thumbnails/advanced-c-inheritance-interfaces-delegates-exceptions/572629.png","ImageObject",442,249,{"name":88,"@type":89},"dbqoiu","Person",{"url":68,"name":91,"@type":92},"DocShare","Organization","application/pdf","2026-10-19","2026-10-13",true,{"@type":98,"interactionType":99,"userInteractionCount":76},"InteractionCounter",{"@type":100},"ViewAction",{"@type":102,"mainEntity":103},"FAQPage",[104,110,114,118],{"name":105,"@type":106,"acceptedAnswer":107},"构造函数在继承中如何处理？","Question",{"text":108,"@type":109},"构造函数不会被继承。子类需要以自己的方式进行构造与初始化。","Answer",{"name":111,"@type":106,"acceptedAnswer":112},"什么时候需要用 override，override 的要求是什么？",{"text":113,"@type":109},"只有声明为 virtual 的方法才能被重写。重写方法必须使用 override 声明，且方法签名（参数数量与类型、可见性等）必须与基类一致。",{"name":115,"@type":106,"acceptedAnswer":116},"new（隐藏）与重写（override）有什么关键区别？",{"text":117,"@type":109},"new 会隐藏同名成员，让编译期依据静态类型选择成员；override 则形成真正的多态行为，调用通常依据接收者的动态类型。文中通过同一对象在不同静态类型引用下调用不同 WhoAreYou() 展示了差异。",{"name":119,"@type":106,"acceptedAnswer":120},"“脆弱基类”问题在本文中如何产生？",{"text":121,"@type":109},"当基类后续发布新版本并改变基类方法内部调用链时，若子类未重新编译，它仍依赖旧基类版本的实现，从而可能导致预期行为不生效；重新编译后编译器会要求将相关方法标为 new 或 override。","https://schema.org",{"og:url":78,"og:type":124,"og:title":59,"og:site_name":91,"og:description":61},"article",{"robots":126,"canonical":78},"index,follow",{"doc_id":128,"site_id":56},572629,1792382656,{"code":4,"msg":5,"data":131},{"doc_id":128,"user_id":132,"nickname":88,"user_avatar":133,"doc_module":9,"category_id":8,"category_name":11,"doc_title":59,"doc_description":61,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":76,"is_deleted":4,"is_public":9,"is_downloadable":9,"audit_status":9,"page_count":139,"language":140,"language_code":57,"site_id":56,"html_lang":57,"table_of_contents":141,"faqs":142,"seo_title":143,"seo_description":61,"update_tm":144,"read_time":145},3985747862462,"https://ap-avatar.wpscdn.com/davatar_3d24733baf745e90a7e4bdd5f77d97b2","Advanced C\\#  \nH.Mössenböck University of Linz, Austria [moessenboeck@ssw.uni-linz.ac.at](moessenboeck@ssw.uni-linz.ac.at)  \nContents  \n• Inheritance  \n• Interfaces  \n• Delegates  \n• Exceptions  \n• Namespaces and Assemblies  \n• Attributes  \n• Threads  \n• XML Comments  \nInheritance  \nSyntax  \nclass A { // base class  \nint a;  \npublic A() {...}  \npublic void F() { ...}}  \nclass B : A { // subclass (inherits from A, extends A ) int b;  \npublic B() {...}  \npublic void G () { ...}}  \n• B inherits a and F(), it adds b and G()  \n- constructors are not inherited  \n- inherited methods can be overridden (see later)  \n•  Single inheritance: a class can only inherit from one base class, but it can implement multiple interfaces.  \n• A class can only inherit from a class, not from a struct.  \n• Structs cannot inherit from another type, but they can implement multiple interfaces.  \n• A class without explicit base class inherits from object.  \nAsignments and Type Checks  \nclass A { ...}  \nclass B : A { ...}  \nclass C: B { ...}  \nAssignments  \nA a = new A(); // static type of a: the type specified in the declaration (here A )  \n// dynamic type of a: the type of the object in a (here also A )  \na = new B(); // dynamic type of a is B  \na = new C(); // dynamic type of a is C  \nB b = a; // forbidden ; compilation error  \nRun time type checks  \na = new C();  \nif (a is C ) ... // true, if dynamic type of a is C or a subclass; otherwise false if (a is B ) ... // true  \nif (a is A ) ... // true, but warning because it makes no sense  \na = null;  \nif (a is C ) ... // false: if a == null, a is T always returns false  \nChecked Type Casts  \nCast  \nA a = new C();  \nB b = (B) a; // if (a is B ) stat.type(a ) is B in this expression ; else exception C c = (C) a;  \na = null;  \nc = (C) a; // ok Î null can be casted to any reference type  \nas  \nA a = new C();  \nB b = a as B; // if (a is B) b = (B)a; else b = null;  \nC c = a as C;  \na = null;  \nc = a as C; // c == null  \nOverriding of Methods  \nOnly methods that are declared as virtual can be overridden in subclasses  \nclass A {  \npublic void F() { ...} // cannot be overridden  \npublic virtual void G () { ...} // can be overridden in a subclass}  \nOverriding methods must be declared as override  \nclass B : A {  \npublic void F() { ...} // warning: hides inherited F() Î use new  \npublic void G() { ...} // warning: hides inherited G() Î use new  \npublic override void G() { // ok: overrides inherited G  \n... base.G(); // calls inherited G()  \n}  \n}  \n• Method signatures must be identical  \n- same number and types of parameters (including function type)  \n-  same visibility (public, protected, ...) .  \n• Properties and indexers can also be overridden (virtual, override) .  \n• Static methods cannot be overridden.  \nDynamic Binding (simplified)   \nclass A {  \npublic virtual void WhoAreYou() { Console.WriteLine(\"I am an A\" ); }}  \nclass B : A {  \npublic override void WhoAreYou() { Console.WriteLine(\"I am a B\"); }}  \nA message invokes the method belonging to the dynamic type of the receiver  \n(not quite true, see later)  \nA a = new B();  \na.WhoAreYou(); // \"I am a B\"  \nEvery method that can work with A can also work with B void Use (A x) {  \nx.WhoAreYou();  \n}  \nUse(new A()); // \"I am an A\"  \nUse(new B()); // \"I am a B\"  \nHiding   \nMembers can be declared as new in a subclass.  \nThey hide inherited members with the same name.  \nclass A { public int x;  \npublic void F() { ...}  \npublic virtual void G() { ...}}  \nclass B : A { public new int x;  \npublic new void F() { ...}  \npublic new void G () { ...}}  \nB b = new B();  \nb.x = ... ; // accesses B.x  \nb. F(); ... b.G(); // calls B. F and B.G  \n((A)b) .x = ... ; // accesses A.x !  \n((A)b) . F(); ... ((A)b) .G(); // calls A. F and A.G !  \nDynamic Binding (with hiding)   \nclass A {  \npublic virtual void WhoAreYou() { Console.WriteLine(\"I am an A\" ); }}  \nclass B : A {  \npublic override void WhoAreYou() { Console.WriteLine(\"I am a B\"); }}  \nclass C : B {  \npublic new virtual v","cbCaissK7evHSmWW","https://ap.wps.com/l/cbCaissK7evHSmWW","pdf",499435,62,"English","# Inheritance\n## Syntax\n## Assignments and Type Checks\n## Runtime Type Checks\n## Checked Type Casts\n## as and Null Handling\n## Overriding of Methods\n## Dynamic Binding (simplified)\n## Hiding\n## Dynamic Binding (with hiding)\n## Fragile Base Class Problem","[{\"question\":\"构造函数在继承中如何处理？\",\"answer\":\"构造函数不会被继承。子类需要以自己的方式进行构造与初始化。\"},{\"question\":\"什么时候需要用 override，override 的要求是什么？\",\"answer\":\"只有声明为 virtual 的方法才能被重写。重写方法必须使用 override 声明，且方法签名（参数数量与类型、可见性等）必须与基类一致。\"},{\"question\":\"new（隐藏）与重写（override）有什么关键区别？\",\"answer\":\"new 会隐藏同名成员，让编译期依据静态类型选择成员；override 则形成真正的多态行为，调用通常依据接收者的动态类型。文中通过同一对象在不同静态类型引用下调用不同 WhoAreYou() 展示了差异。\"},{\"question\":\"“脆弱基类”问题在本文中如何产生？\",\"answer\":\"当基类后续发布新版本并改变基类方法内部调用链时，若子类未重新编译，它仍依赖旧基类版本的实现，从而可能导致预期行为不生效；重新编译后编译器会要求将相关方法标为 new 或 override。\"}]","Advanced C# - Inheritance, Interfaces, Delegates, Exceptions | PDF",1791928554,22]