override (C# Reference)
https://msdn.microsoft.com/en-us/library/ebca9ah3.aspx
The override modifier is required to extend or modify the abstract or virtual implementation of an inherited method, property, indexer, or event.
Example
In this example, the Square class must provide an overridden implementation of Area because Area is inherited from the abstract ShapesClass:
abstract class ShapesClass { abstract public int Area(); } class Square : ShapesClass { int side = 0; public Square(int n) { side = n; } /// <summary> /// Area method is required to avoid a compile-time error. /// </summary> /// <returns></returns> public override int Area() { return side*side; } internal static void Method() { Square sq = new Square(12); Console.WriteLine("Area of the square = {0}", sq.Area()); } interface I { void M(); } abstract class C : I { public abstract void M(); } }
An override method provides a new implementation of a member that is inherited from a base class.
The method that is overridden by an override declaration is known as the overridden base method.
The overridden base method must have the same signature as the override method.
For information about inheritance, see Inheritance (C# Programming Guide).
You cannot override a non-virtual or static method.
The overridden base method must be virtual, abstract, or override.
An override declaration cannot change the accessibility of the virtual method.Both the override method and the virtual method must have the same access level modifier.
You cannot use the new, static, or virtual modifiers to modify an override method.
An overriding property declaration must specify exactly the same access modifier, type, and name as the inherited property, and the overridden property must be virtual, abstract, or override.
For more information about how to use the override keyword,
see Versioning with the Override and New Keywords (C# Programming Guide)
andKnowing when to use Override and New Keywords.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了